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

4. Game #3, CometCrusher > Time for action — creating some explosions

Time for action — creating some explosions

  1. To spawn an explosion, create an method called SpawnExplosion. The parameters will be the particle amount, and the center position of the explosion.
    Method SpawnExplosion:Int(c:Int, xp:Float, yp:Float)
    
  2. Add a FOR loop from 1 to the amount of particles.
    For Local i:Int = 1 To c
    
  3. Create a local object of the particle from the sprite atlas.
    Local explo:ftObject = eng.CreateImage(atlas, 0,112,16,16, xp, yp)
    
  4. Scale and rotate it randomly.
    explo.SetScale(Rnd(3,15)/10)
    explo.SetAngle(Rnd(0,359))
    
  5. Add a random spin and speed.
    explo.SetSpin(Rnd(-4,4))
    explo.SetSpeed(Rnd(1,2))
    
  6. Reset the layer to layerFX and create an object timer with the ID tmObjRemove to remove the particle after a random time between 100 to 2000 milliseconds.
    explo.SetLayer(layerFX)
    eng.CreateObjTimer(explo, 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 Trial