Java Reference
In-Depth Information
C H A P T E R 10
■ ■ ■
Effects: Physics and Particles
Particles are capable of creating some eye-catching animations that produce vibrant and fluid effects.
Physics engines, on the other hand, create animations that satisfy our sense of motion. Combining these
two excellent effects offers the best of both worlds, and this chapter explores two examples of
intertwining physics with particles.
Particles as Bodies
In Chapter 6 I used the open source physics engine Phys2D to implement a number of physics-based
examples in JavaFX. This chapter will continue to use Phys2D because it provides so much functionality.
As you'll recall from Chapter 6, an object in a physics simulation is called a body. This first example
explores how to implement a particle system where each particle is a body. Basically, the particle emitter
will create particles that are JavaFX Nodes and have reference to a Body . As the World is updated and the
location of the Body changes, the location of the Node is updated to reflect this.
This is different from the original particle examples in Chapter 6 wherein each Node updated its
location based on a set of fixed parameters. Figure 10-1 shows a particle system that utilizes physics.
Search WWH ::

Custom Search