Java Reference
In-Depth Information
Stop {offset: 0.5751 color: Color.rgb(0x66,0x47,0x19)},
Stop {offset: 0.6603 color: Color.rgb(0x6e,0x4c,0x1a)},
Stop {offset: 0.7159 color: Color.rgb(0x76,0x51,0x1b)},
Stop {offset: 0.7582 color: Color.rgb(0x7e,0x56,0x1c)},
Stop {offset: 0.7927 color: Color.rgb(0x86,0x5b,0x1d)},
Stop {offset: 0.8220 color: Color.rgb(0x8e,0x60,0x1e)},
Stop {offset: 0.8478 color: Color.rgb(0x96,0x65,0x1f)},
Stop {offset: 0.8707 color: Color.rgb(0x9e,0x6a,0x20)},
Stop {offset: 0.8914 color: Color.rgb(0xa6,0x6e,0x20)},
Stop {offset: 0.9104 color: Color.rgb(0xae,0x73,0x21)},
Stop {offset: 0.9279 color: Color.rgb(0xb6,0x78,0x22)},
Stop {offset: 0.9441 color: Color.rgb(0xbe,0x7d,0x23)},
Stop {offset: 0.9593 color: Color.rgb(0xc6,0x82,0x24)},
Stop {offset: 0.9736 color: Color.rgb(0xce,0x87,0x25)},
Stop {offset: 0.9872 color: Color.rgb(0xd6,0x8c,0x26)},
Stop {offset: 1.000 color: Color.rgb(0xde,0x91,0x27)},
stroke: null
content: "M0.31,480.00 L0.31,439.00 Q299.31,318.00 640.31,439.00 L640.31,480.00 Z "
In Listing 11-2, a LinearGradient is defined with 17 Stops , but in Illustrator this gradient is defined
with just 2 colors. I am not exactly sure why all of the extra Stops are included. Perhaps the algorithm
Illustrator used for tweening colors is different than that of JavaFX. Since gradients are a performance
pain point in JavaFX, it makes sense to simplify these gradients to use just 2 Stops . There might be a
fidelity issue with doing this, but I couldn't tell the difference between the LinearGradient with 17 Stops
and the simplified LinearGradient with only 2 Stops . In Listing 11-1, the functions that initialize the two
GameAssetUIs use the function simplifyGradient to recursively traverse the Node tree and simplify all
LinearGradients . Be warned that if your Illustrator file uses gradients, which should have more than 2
Stops, the simplifyGradients function will not correctly preserve the intended look.
The function initStartScreen creates a Timeline for animating the SpotLight by calling the function
addLights . The function addLights creates a Lighting effect with a SpotLight and applies it to the Group
backPanelGroup2 . The Group backPanelGroup2 contains the ceiling and wall of the circus tent. The
SpotLight that is created is positioned in the center of the Group backPanelGroup2 , and the Timeline anim
is then created to change the location where the SpotLight is pointing. The Timeline anim is returned
from the function addLights to allow the animation to be started and stopped. This is important because
applying lighting effects is computationally expensive and should be turned off when not in use.
The functions initStartScreen and initAboutScreen use the function removeFromParent to get rid of
unwanted content. This is a simple utility function found in Listing 11-1 that I find handy, because
Node.parent returns a Node of type Parent , which is not very useful. Both of the classes Scene and Group
extend Parent , since these are the two types that might contain a Node . Unfortunately the class Parent
does not require an attribute named content . Rather it requires the function removeFromParent to cast
node.parent to the correct class before deleting it from the content that contains it.
The last thing the functions initStartScreen and initAboutScreen do is create buttons out of some
of the Nodes in the fxz content. The function makeButton does not create an instance of
javafx.scene.control.Button , but instead just adds button-like functionality to the Node passed to the
function. Adding some event listeners to the Node does this. The onMouseClicked attribute is used to call
the function action when the user clicks on the Node , and setting blocksMouse to true prevents the click
from being processed by some other listening node. The two properties onMouseEntered and
Search WWH ::

Custom Search