Java Reference
In-Depth Information
var result = max - random.nextFloat()*max*2;
return result;
}
public function simplifyGradients(node:Node):Void{
if (node instanceof Shape){
var shape = node as Shape;
if (shape.fill instanceof LinearGradient){
var linearGradient = (shape.fill as LinearGradient);
if (sizeof(linearGradient.stops) > 2){
var newStops:Stop[];
insert linearGradient.stops[0] into newStops;
insert linearGradient.stops[sizeof(linearGradient.stops)-1] into newStops;
var newGradient = LinearGradient{
endX: linearGradient.endX
endY: linearGradient.endY
proportional: linearGradient.proportional;
startX: linearGradient.startX
startY: linearGradient.startY
stops: newStops;
}
shape.fill = newGradient;
}
}
}
if (node instanceof Group){
for(n in (node as Group).content){
simplifyGradients(n);
}
}
}
In Listing 11-1 the variables
startScreen
and
aboutScreen
are instances of
GameAssetsUI
. Each
GameAssetsUI
is a complete set of
Nodes
from the original Illustrator file. The functions
initStartScreen
and
initAboutScreen
prepare
startScreen
and
aboutScreen
for use in the game. The function
initStartScreen
simplifies the gradients, creates an animation for the spotlight, removes a number of
unwanted
Nodes
and turns the
Nodes
startScreen.startButton
and
startScreen.aboutButton
into
buttons. Let's take a look at each of these steps.
The gradients generated when exporting from Illustrator are oddly complex. Listing 11-2 shows one
of these gradients.
Listing 11-2.
GameAssets.fxz (partial)
SVGPath {
id: "floor"
fill: LinearGradient{proportional: false startX: 320.31 startY:385.22 endX: 320.31
endY: 480.00 stops: [
Stop {offset: 0.005 color: Color.rgb(0x5e,0x43,0x19)},