Collision Event
Previous Top Next

Collision event occurs when two sprites collide.
You could find the involved sprites with Sprite1 and Sprite2 properties.

Example:
Sub gw_Collision
'This event occurs when two sprites collide.
      spr1.Value = gw.Sprite1 'Get the two sprites.
      spr2.Value = gw.Sprite2
      If gw.SpriteIndex(spr1.Value) = 0 OR gw.SpriteIndex(spr2.Value) = 0 Then Return
      'If one of the sprites is the explode sprite (which is the first sprite) we won't do anything.
      spr1.MarkedForDelete = true 'Delete these sprites.
      spr2.MarkedForDelete = true
      explodeSprite.X = (spr1.X + spr2.X)/2 - explodeSprite.Width / 2 'Set the explode sprite position
      explodeSprite.Y = (spr1.Y + spr2.Y) /2 - explodeSprite.Height / 2
      explodeSprite.CurrentFrame = 0 'Start the exploding animation from the first frame.
      explodeSprite.LifeTimeCounter = 5 'Activate the sprite for 5 ticks.
      Sound("explode.wav") 'Plays the sound.
End Sub