Java Reference
In-Depth Information
KeyFrame{
time: 0s
values: asim => 0.0
},
KeyFrame{
time: 5s
values: asim => 360.0
},
]
}
insert group into exampleGroup.content;
anim.play();
}
In Listing 4-5, each of the three shapes, rect , circle, and triangle are created with a DistantLight
applied. Each DistantLight has its elevation set to 45.0 and its azimuth bound to the variable azim . All
three shapes are added to a group that has a DropShadow applied. The DropShadow has its offsetX and
offsetY properties bound to a simple trigonometric function that converts the angle of the azim to an x
and y offset.
The animation anim changes the value of azim from 0.0 to 360.0 and back again; this causes each
DistantLight to appear to rotate around each object, while the DropShadow is drawn on the opposite side.
Further Considerations
The examples shown here just touch on what is possible with animated lights. For instance, each light
also allows a color to be set or a texture to be used. There is much to explore with lighting, not only with
static lights but animated ones as well. Imagine an application, for example, where pressing a button
lights up other nearby controls, or where default choices are highlighted by a flickering light.
Once again, designers need to keep in mind the graphics capabilities of the platform they're working
on. This in turn will allow their applications to make the most of the platform they run on, whether
JavaFX or another.
It is also important to consider that applying a lighting effect is not a cheap operation. Though the
implementation of JavaFX is opaque, you can assume that each lighting effect requires JavaFX to
rasterize each node the effect is applied to. Platforms where hardware acceleration is present will
mitigate this performance issue, but too many lights on a less capable machine will prevent the
application from working properly.
Summary
This chapter explored the basics of lighting in JavaFX and showed how lights can be animated to amplify
the 3D effect they produce when motionless. Distant light is useful when lighting from a general
direction is required, while point and spot lights bring the lights into the scene. Finally, this chapter
looked at combining shadows with lights to complete the 3D illusion.
Search WWH ::




Custom Search