O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required