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 the particle emitter class

Just like with the Enemy class, we will create the emitter class in one batch:

  1. Add a new class to our script, called ParticleEmitter. Again, this one isn't extended from anything.
    Class ParticleEmitter
    
  2. Add a field for the emitter position.
    Field xp:Float
    Field yp:Float
    
  3. Now, insert a field for the time that is left for the emitter to create particles.
    Field timeLeft:Float
    
  4. The last field in the data section is the kind field. Some particles will be colored, and so we need to tell the emitter to do that.
    Field kind:Int
    
  5. The New constructor method will have the x and y positions as parameters. Also it will take the time factor and the kind flag as values.
    Method New(x:Float, y:Float, time:Int, knd:Int) ...

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