Sprite Library question

Leginus

Member
Licensed User
I have a stationary sprite in the middle of the screen and other sprites falling from the top of the screen to the bottom(using sprite direction and velocity). When a sprite collides with the sprite in the middle of the screen I try to move the colliding sprite to the right until the collision is over. However, the collision routine moves both the colliding sprite and the sprite in the middle when using this code

B4X:
Sub gw_Collision
    Spr1.Value = gw.Sprite1 
    spr2.Value = gw.Sprite2
    spr2.x=spr2.x+1
End Sub
Is this a bug with the sprite library, e.g. that is cannot differentiate between spr1.x and spr2.x, or am I missing the point somewhere

thanks
Leginus
 

Erel

Administrator
Staff member
Licensed User
If I understand correctly this code will run several times in each set of collisions.
The order of the sprites (gw.Sprite1 and gw.Sprite2) can be different each time and therefore cause both sprites to move.
The best solution is to bind the stationary sprite to one object and use this object to move it:
B4X:
Sub gw_Collision
  If gw.SpriteIndex(spr1.Value) = IndexOfSpecialSprite OR gw.SpriteIndex(spr2.Value) = IndexOfSpecialSprite Then
  SpecialSprite.x = SpecialSprite.x + 1
 End If
End Sub
 
Top