Worng Sprite Move?

fjsantos

Member
Licensed User
Hi all.

I try using sprite library move, but its seems wrong.

I do...

B4X:
Sub GameForm_KeyPress(specialKey)
   Select specialKey
      Case cRightKey, 80
         Move(0, 22)
      Case cLeftKey, 79
         Move(180, 22)
   End Select
End Sub

Sub Move(d, v)
   CellSprite.Direction = d
   CellSprite.Velocity = v
   GameGameWindow.Tick
End Sub

Then when i changed move key, its do a last move on opposite direction, I mean if I do 'Right, Right, Right, Left', last move will be Right.

Another question is if I don't like to do any move (move some sprites and not others), i have to put velocity to 0 or I can put direction, to -1 for example?

Thanks in advance!

Best Regards, fjsantos.
________
buy cheap vaporizer
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The Sprite library which is based on this project: Pocket PC and SpriteHand components first draws the sprites to an off-screen buffer and then draws this buffer to the screen.
This method makes the animation more smooth.
As it is implemented, on every tick the offscreen bitmap is drawn and then it is updated with the new positions.
Changing this logic is more complicated than it might seem.

The solution is to handle the position yourself.
Set the velocity to 0 and just update CellSprite.X and CellSprite.Y.
 
Top