Java Reference
In-Depth Information
width: 200
textFill: Color.WHITESMOKE
font: Font{
size: 10;
}
}
var emitter = Emitter{
particleRadius: bind radiusSlider.value;
particleSpeed: bind speedSlider.value;
particleDuration: bind (durationSlider.value as Integer);
frequency: bind frequencySlider.value * 1s
translateX: 320
translateY: 240
}
Stage {
title: "Chapter 2 - Example 2"
width: 640
height: 480
scene: Scene {
fill: Color.BLACK
content: [
emitter,
particleCountLabel,
frequencyLabel,
frequencySlider,
radiusLabel,
radiusSlider,
speedLabel,
speedSlider,
durationLabel,
durationSlider
]
}
}
Listing 2-5 shows four Sliders , each controlling one of the four attributes exposed in the class
Emitter . Notice in the declaration of the Emitter that the four new attributes are set using the keyword
' bind '. In this way, when a user adjusts a slider, the value of the attribute adjusts automatically.
There are a number of labels describing the controls, and one that shows the number of particles in
the scene. This number is important when fine-tuning an effect, as too many particles can cause
performance issues and dropped frames.
The last class to change is Particle , as shown in Listing 2-6.
Listing 2-6. Particle.fx (partial)
public class Particle extends Circle{
public-init var initialSteps:Integer;//number of steps until removed
public-init var speed:Number;//pixels per step
Search WWH ::




Custom Search