Java Reference
In-Depth Information
function run():Void{
worldUpdater.play();
var sparksButton = Button{
text: "Sparks"
action: sparks
}
var fireballsButton = Button{
text: "Fireballs"
action: fireballs
}
var buttons = VBox{
translateX: 32
translateY: 32
spacing: 12
content: [sparksButton, fireballsButton]
}
Stage {
title: "Chapter 11"
width: 640
height: 480
scene: Scene {
fill: Color.BLACK;
content: [buttons, obstacles, particles]
}
}
}
function sparks():Void{
clear();
for (x in [1..64]){
addWorldNode(Peg{
radius: 4
translateX: x*10
translateY: 400
});
}
var emitter = SparkEmitter{
x: 640/2
y: 130
}
addEmitter(emitter);
}
The function
run
sets up the scene and the buttons that present each example. The function
sparks
is the entry point for this first example—it simply creates a number of
Pegs
and a
SparkEmitter
. The
Pegs
create the line of circles seen in Figure 10-1, while the
SparkEmitter
specifies from where the sparks
should come. The
Pegs
are added by the function
addWorldNode
; the
Emitter
is added by the function
addEmitter
.
In this example an
Emitter
is not a JavaFX
Node
. It is just an object that controls when particles are
added, though it does specify where the particles are created. In Chapter 6 on particles, an emitter is a