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

Time for action — spawning an explosion 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) Set the default layer to g.layerGFX. SetDefaultLayer(g.layerGFX) Start a FOR loop as a counter ranging from 1 to amount. For Local i:Int = 1 To amount Create a new particle object. Local explo:ftObject = CreateImage(g.atlas, 128, 0,32,32, xp, yp) 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)) Play the explosion sound. g.sndExplo.Play() 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)) 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 shownWhen a particle is spawned

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free Trial


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