Box2D Forums

It is currently Sat May 25, 2013 9:38 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Sep 21, 2008 1:11 am 
Offline

Joined: Sun Sep 21, 2008 12:54 am
Posts: 2
Attached is some code that I've knocked together over the last week or so implementing a Engine on top of JBox2D in JavaFX. It uses the scene-graph objects from JavaFX to render the Circles and Polygons of JBox2D. So you get code like...

Code:
    private function updateCircleShape(nextShape : Shape, nextBody : Body) : Void {
        var circleShape = nextShape as CircleShape;
        var nextCircle = circleShape.getUserData() as Circle;

        if(nextCircle == null) {
            nextCircle = Circle {
                transform : myTransform;
                stroke : Color.RED;
                strokeWidth: 0.2;
            }
            insert nextCircle into myGroup.content;
            circleShape.setUserData(nextCircle);
        }

        nextCircle.centerX = nextBody.getPosition().x;
        nextCircle.centerY = nextBody.getPosition().y * -1;
        nextCircle.radius = circleShape.getRadius();
    }


Instead of following the DebugDraw approach which redraws the shape each time the JavaFX approach is to update the (x,y) coordinates of the "Node" object in the scene and let JavaFX take care of actually rendering it.

So it's all pretty rough around the edges but basically the best way to build it is to simply unpack the attached source zip into the JBox2D source directory and then build JBox2D just like you would normally.

Now the tricky part is... ...so that I could reuse the test classes that came with JBox2D I had to add a public constructor to AbstractExample and then any of the test classes I wanted to run.

Code:
        public AbstractExample() {
            createWorld();
            create();
        }


And then....

Code:
public class Domino extends AbstractExample {

    public Domino() {
        super();
    }



Anyway if people are interested here it is.

Thoughts or feedback most welcomed.

Btw I don't know why the DominoTower test class doesn't work yet.


Attachments:
jbox2djfxengine.zip [5.25 KiB]
Downloaded 222 times
Top
 Profile  
 
PostPosted: Wed Nov 30, 2011 2:25 pm 
Offline

Joined: Wed Nov 30, 2011 2:17 pm
Posts: 2
Check this sample application of JBox2D with JavaFX 2 at http://thisiswhatiknowabout.blogspot.com/2011/11/hello-world-jbox2d-with-javafx-20.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: psbot [Picsearch] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group