L Leginus Member Licensed User Longtime User Mar 12, 2008 #1 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 Code: 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
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 Code: 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 B4X founder Staff member Licensed User Longtime User Mar 13, 2008 #2 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: Code: 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
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: Code: 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