Java Reference
In-Depth Information
Update the location and rotation of each Node .
Go back to step 2.
The following examples will show how to set up a JavaFX application to use Phys2D, as well as how
to use a number of features in Phys2D.
Simple Example
For this first example, the Phys2D jar file must be downloaded and included in the projects classpath .
Once Phys2D is on the classpath, the classes in that library may be instantiated in a JavaFX application
in the same way as any Java class is instantiated in JavaFX, by simply calling the constructor. The code in
Listing 6-1 shows how to set up the basic components of a JavaFX application using Phys2D.
Listing 6-1. Main.fx
var random = new Random();
var worldNodes:WorldNode[];
var group = Group{}
var world = new World(new Vector2f(0,1200), 1);
var worldUpdater = Timeline{
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame{
time: 1.0/30.0*1s
action: update;
public function update():Void{
for (worldNode in worldNodes){
public function addWorldNode(worldNode:WorldNode):Void{
insert (worldNode as Node) into group.content;
insert worldNode into worldNodes;
for (body in worldNode.bodies){
for (joint in worldNode.joints){
public function reset():Void{
Search WWH ::

Custom Search