Hi
This is really basic stuff but I have used the "Moving sprites" example in the docs to make a selection of my sprites move at different speed to their destination.
Here is the code from the docs:
SetVirtualResolution ( 320, 480 )
CreateSprite ( LoadImage ( "background4.jpg" ) )
image = LoadImage ( “lime.png” )
sprite = CreateSprite ( image )
do
Print ( "Touch or click the screen to move the" )
Print ( "sprite to that location" )
if GetPointerPressed ( ) = 1
x = GetPointerX ( )
y = GetPointerY ( )
if ( move = 0 )
move = 1
originalX# = GetSpriteX ( sprite )
originalY# = GetSpriteY ( sprite )
destinationX# = x
destinationY# = y
distanceX# = destinationX# - originalX#
distanceY# = destinationY# - originalY#
distanceFromAtoB# = sqrt ( ( distanceX# * distanceX# ) + ( distanceY# * distanceY# ) )
if ( distanceFromAtoB# <> 0.0 )
directionX# = distanceX# / distanceFromAtoB#
directionY# = distanceY# / distanceFromAtoB#
endif
endif
endif
if ( move > 0 )
newX# = originalX# + directionX# * move
newY# = originalY# + directionY# * move
if ( move < distanceFromAtoB# )
move = move + 2
else
move = 0
endif
SetSpritePosition ( sprite, newX#, newY# )
endif
Sync ( )
loop
If I add more than 2 to in the "move = move +2" command - some of the sprites will not land at their exact destination.
Since the example uses float variables - how can I make sure the sprites land at their destination?
I have tried to use "round" or "floor" - but with no luck...
I'm a donut....
Would you help a dount?