Java Reference
In-Depth Information
Listing 6-8. Main.fx
function teetertotter ():Void{
addWorldNode(Ball{translateX: 320-20-random.nextInt(120), translateY:
10+random.nextInt(300), radius: 10+random.nextInt(10)});
addWorldNode(Ball{translateX: 320+20+random.nextInt(120), translateY:
10+random.nextInt(300), radius: 10+random.nextInt(10)});
addWorldNode(Wall{width: 500, height: 16, translateX: 320, translateY: 440});
addWorldNode(TeeterTotter {translateX: 320, translateY: 400});
The function teetertotter in Listing 6-8 shows how the WorldNodes are added to the application.
Again, the interesting part is in the implementation of the class TeeterTotter , shown in Listing 6-9.
Listing 6-9. TeeterTotter.fx
public class TeeterTotter extends Group, WorldNode{
var barWidth = 300.0;
var barHieght = 5.0;
var crossbar = Rectangle{
width: barWidth;
height: barHieght;
fill: Color.GREEN;
arcWidth: 3
arcHeight: 3
bodies[0] = new Body(new net.phys2d.raw.shapes.Box(barWidth,barHieght),50);
bodies[0].setPosition(translateX, translateY);
var points:Vector2f[];
insert new Vector2f(0,0) into points;
insert new Vector2f(20,30) into points;
insert new Vector2f(-20,30) into points;
bodies[1] = new StaticBody(new net.phys2d.raw.shapes.ConvexPolygon(points));
bodies[1].setPosition(translateX, translateY);
joints[0] = new DistanceJoint(bodies[0], bodies[1], new Vector2f(0,barHieght/2.0),
new Vector2f(0,0), 0);
var fulcrum = javafx.scene.shape.Polygon{
Search WWH ::

Custom Search