2017년 1월 8일 일요일

how do I use touch events to drop sprites and then add a controller to them


Help, Is it possible to use the touch event to create (already made) sprites on the screen where I touch the screen (much like drawing the "ball in the tutorial')
but then have each touch given a value (like sprite (1), then another touch results with sprite (2), then another touch triggers, sprite (3) and so on.
Then I would like these sprites which should all be different variable be able to do simple things .
--One would be store location its local in a database so I can redraw it on the screen later,  ( I know how to connect database to the app inventor already)
--Another feature would be to have a sprite that has a touch event put on it to trigger a function (when you press the you created on the screen it triggers an event)

So far all I have found in the tutorials is that I can upload a sprite and put it on the screen , or I can use the draw function to leave dots on the screen. I have no clue how to give either one of those things an assigned variable and I have no idea how I can trigger evens to those sprites I create (simple counter, or an alert or event) .
Of course I see how events are tied to these classes (?), but how does one assign the sprite after its initially created?

Any help would be great, you just have to point me in the general direction . Thanks !

--
If you have not read this, http://www.appinventor.org/bookChapters/chapter17.pdf  , do so now.   The chapter explains screen coordinates.

Yes, it is possible to get the screen coordinates by touching the screen... you can get the screen coordinates by using the Canvas controls  and also get a Sprites coordinates by touching the sprite.   This can get complicate.  Yes, you can capture the coordinates and store them.

What you can do with the Sprites and Canvas are summarized here:  Drawing and Animation Components - App Inventor for Android  

To do most (if not all) of the other things, read in the same eBook the chapters 14 to 22.

Now you need to try some blocks and experiment with a small, new Project.   Put a Canvas on the screen, put a Sprite into the Canvas and an image into Media to use with your sprite.

--
Thank you for the information. I did previously read the screen coordinates and how to capture them, and I also read some Database stuff that expands that technique so that I can store and retrieve them.

And yes I have already put a sprite onto a canvas. There was a tutorial on how to tap the screen and make a circle. The circle was defined/ created by grabbing there x,y coordinates and putting a radius where your finger hits the canvas... O totally understand that.

But what I dont understand how to assign a value to sprite (1) the first tap and then to sprite (2) the second and so on. Of course I am looking to build an array that stores the original tap down location to sprite(1) and sprite (2) and the rest of them.

So I am hoping for the tutorial or information that comes after I follow these two. An example of what I want to create could be a sprite of a foot print. Each step signifies a step. I may retap or reposition any footstep after its created by tapping (?) that tap on the newly created sprite would trigger an event (lets just say each footstep put down counts on the screen and if you tap it it goes away and the count goes down. ) Once Im happy with the amount of footprints I put down, the file is saved to the db so that the sprites can just be put assigned there without tapping (it is recreated) .

I know that is a terrible example but I really dont understand how to take the canvas to sprite to the next level. How does one assign variables to create the new sprites and where can I find the information on that. The current link you sent me doesnt actually demonstrate that, instead it allows sprites on screen to move, and have events set on them.  (like the billard balls) but those are sprites that are individually predefined, not copies that are given a sequential id .

But just so we are clear I really appreciate you answering this and taking the time to do so, its my fault for not being specific, but only 1/2 of my question has been answered, Im looking to see if the hard part can be done with app inventor. (otherwise Im going to just write some android code )
--
1) you can not create sprites with code, you can only make sprites that already exist appear and disappear.   For instance, you can have a right foot and left foot sprite and display them alternately.. however, if you want to show the foot print tracks... you need a sprite image for EACH of the sprites you display.

2) Keeping track of sprites:   You probably can use the Any component blocks

to make the sprite "walk"          Yes, you can hide the footprint    Sprite.Visible = false.

When you use the code shown previously in this thread ...that shows where you touched,  capture that information to a list or a text file.

I can't write your app for you.    Making a counter is easy ...you could  search in the forum using the Search for topics box to the right of the colorful google at the top of this page for  counter  .  You will need a variable to keep track of the "taps."    Sprites have Touched, TouchedUp and TouchedDown event handlers ; put the code you want to execute when an event happens.  I believe it is possible to do most, if not all, you say you want to do with app inventor.   You have to try, the tools are there to store and recall information. Can AI2 do everything you want?  I do not know.   Try Eclipse or Android Studio.  They can do more than AI but use Java..most users find AI2 significantly easier to use, however it's tool box is limited.  

What code have you written so far?   The way to learn to do this is the way I and others learned...by experimenting.  There is no tutorial showing how to do exactly what you want to do.

--

댓글 없음:

댓글 쓰기