How to move a sprite to the position touched?

132 views
Skip to first unread message

Yash Wadhwani

unread,
Oct 25, 2016, 7:18:02 AM10/25/16
to MIT App Inventor Forum

This is what I've achieved to do so far :

The buttons provide pixel by pixel movement but I've to keep pressing them again and again to reach a point.

The Canvas event directly puts the sprite to the position touched. 


I want to move the sprite from X1,Y1 pixel by pixel and keep moving it until it reaches the position touched on the screen that is X2,Y2.

Please help!

Ghica

unread,
Oct 25, 2016, 11:28:48 AM10/25/16
to MIT App Inventor Forum
What you could do, is give your sprite Billy a speed, point it to the direction of x,y (use the call ImageSprite.PointTowards target block).
Start a Clock with a rather short timer and at each Timer event, check whether the sprite is close enough. If yes, stop the sprite and the timer.
Instead of the clock, you could place a very small sprite (I think it can be transparent, but not invisible) at the x,y position and use when ImageSprite.CollidedWith other.
If other is your very small sprite, you can stop moving Billy.
Cheers, Ghica.

Yash Wadhwani

unread,
Oct 28, 2016, 6:21:09 AM10/28/16
to MIT App Inventor Forum
Thanks for the reply but I couldn't really work it out.
To be more precise I want Billy to move like the main sumo in this game: https://youtu.be/Gj5CwgFUbI0?t=56s
Thanks.

Ghica

unread,
Oct 28, 2016, 7:38:06 AM10/28/16
to MIT App Inventor Forum


Try this. Cheers, Ghica
billy.aia

Yash Wadhwani

unread,
Oct 31, 2016, 10:36:55 AM10/31/16
to mitappinv...@googlegroups.com

Thank you so much Ghica. I was able to achieve what I wanted with just a few edits.  I replaced the target sprite with a blank png image :)


billy_copy2.aia
Reply all
Reply to author
Forward
0 new messages