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
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

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

Chapter 9 Eye candy--particle effects Whenever a gem is removed, you want to enhance the graphical effect by displaying a particle effect or something similar. Particles are usually some animated graphics that change over time and then disappear. 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. 3. 4. 5. 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))