Time for action — spawning an explosion

  1. Add the method SpawnExplosion to the engine class. The parameters are the number of particles and their position.
    Method SpawnExplosion:Int(amount:Int, xp:Int, yp:Int)
    
  2. Set the default layer to g.layerGFX.
    SetDefaultLayer(g.layerGFX)
    
  3. Start a FOR loop as a counter ranging from 1 to amount.
    For Local i:Int = 1 To amount
    
  4. Create a new particle object.
    Local explo:ftObject = CreateImage(g.atlas, 128, 0,32,32, xp, yp)
    
  5. Set its scale, angle, spin, and speed randomly.
    explo.SetScale(Rnd(2,12)/10)
    explo.SetAngle(Rnd(0,359))
    explo.SetSpin(Rnd(-4,4))
    explo.SetSpeed(Rnd(1,2))
    
  6. Play the explosion sound.
    g.sndExplo.Play()
    
  7. Create an object timer, so that the particles will be removed after a random time. The timer ID is g.tmObjRemove.
    CreateObjTimer(explo, g.tmObjRemove, Rnd(100,2000))
    
  8. Close the FOR statement and the method.
    Next
    Return 0
    End
    

What just happened?

This new method will spawn some particles that will be deleted via a timer.

Tick tock… acting on object timer events

Treasure Chest has two situations where a timer is set, and we need to act on it:

  • When the title screen is shown
  • When a particle is spawned
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.71.94