Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Game #8, Treasure Chest > Time for action — spawning an explosion

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))
    

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint