Java Reference
In-Depth Information
addEmitter(FireballEmitter{});
}
Listing 10-5 shows the function fireballs , which sets up the next example. The function creates a
number of Pegs in a sort of Pachinko pattern and adds a FireballEmitter . The class FireballEmitter
creates a number of Fireball particles as Listing 10-6 illustrates.
Listing 10-6. FireballEmitter.fx
public class FireballEmitter extends Emitter{
var emitTimeline = Timeline{
repeatCount: Timeline.INDEFINITE;
keyFrames: KeyFrame{
time: 2s
action: emit;
}
}
function emit():Void{
var fireball = Fireball{
translateX: 100 + Main.random.nextInt(440)
translateY: -30
effect: ColorAdjust{
hue: Main.randomFromNegToPos(1.0);
}
}
Main.addWorldNode(fireball);
Main.addEmitter(fireball);
}
public override function play():Void{
emitTimeline.play();
}
public override function stop():Void{
emitTimeline.stop();
}
}
Listing 10-6 shows the class FireballEmitter , which extends Emitter . This simple class creates a
Timeline that periodically calls emit . The function emit creates a new Fireball with a random color and
sets it loose. Listing 10-7 shows the implementation of Fireball .
Listing 10-7. Fireball.fx
public class Fireball extends Group, WorldNode, Particle, Emitter{
var emitTimeline = Timeline{
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame{
time: 1/15.0*1s
action: emit;
}
}
Search WWH ::




Custom Search