Java Reference
In-Depth Information
fill: Color.BLUE;
translateX: bodies[1].getPosition().getX()-translateX;
translateY: bodies[1].getPosition().getY()-translateY;
}
for (vector in points){
insert vector.getX() into fulcrum.points;
insert vector.getY() into fulcrum.points;
}
insert fulcrum into content;
insert crossbar into content;
effect = lighting;
update();
}
public override function update():Void{
crossbar.rotate = Math.toDegrees(bodies[0].getRotation());
crossbar.translateX = (bodies[0].getPosition().getX() - barWidth/2.0) - translateX;
crossbar.translateY = (bodies[0].getPosition().getY() - barHieght/2.0) - translateY;
}
}
The init function in Listing 6-9 shows how the Bodies are constructed. The Body in bodies[0] is the
'board' of the teeter totter, which is composed of a simple box, much like the Wall class. The triangular
fixed body acts as the fulcrum, and its shape is defined by specifying the points of triangle. The Node that
represents the fulcrum in the scene is constructed by iterating over this list points, creating a JavaFX
Polygon based on those points. Lastly, the update method makes sure to update the position and
rotation of the crossbar as it moves.
Transition Example
Chapter 3 on transitions explored how to transition between two views; this chapter shows how to make
realistic animations with JavaFX and the open source library Phys2D. Why not combine the two?
The code in this example takes a Group that contains a number of Control nodes and creates an
animation that makes it appear as if the Controls are suddenly affected by gravity. In turn, each Control
starts to fall, bouncing off the other Controls . The animation ends when all the Controls have fallen out
of the original bounds of their container, then the second Group of Controls fades in.
You'll find this example in a different package from the rest of this chapter. I found trying to
combine this transition example with the other examples created code that was not suitable for
demonstration. Please find this code in the package org.lj.jfxe.chapter6.transition , and start the
example by running the file TransitionExampleMain .
Search WWH ::




Custom Search