Build 10 classic Flash games and learn game development along the way with this ultra-fast paced game development course.

If you love this blog, this is the book for you.

Buy the book

Get the source code of 12 commercial Flash games, which have been loaded more than 50 million times!

Learn from real world successful examples.

Get it now

Box2D for Flash Games teaches you how to make Flash physics games from scratch with the most advanced features.

Create the new Flash game smashing hit.

Buy the book

Box2D joints: Revolute Joint

After introducing Distance Joints, it’s time to learn something about Revolute Joints.

A Revolute Joint attaches two objects by “pinning” them together at an anchor point which they may revolve around.

The most interesting thing, that I will cover in another post, is the capibility of making motors out of Revolute Joints. Yes… motors… engines… easy to do and ecologic since they don’t need fuel, just some code.

But at the moment let’s see the basic Revolute Joint.

Here it is:

Now let’s see how to make this possible:

Line 16: Declaration of the_rev_joint variable, a b2RevoluteJointDef type

Lines 40-46: Creating a circle in the middle of the stage that will act as a pivot point. In most examples around the web you will find pivot points as tiny, almost invisible boxes. I am making a big one because I think it will be easier to skin it once I will need to do it. Notice at line 41 that the object is static because it has density at zero.

Lines 48-56: Creation of the box that will be tied to the joint. You can virtually place it anywhere, but for an interesting result, it should be in a position where the joint can act as a fulcrum.

Line 57: Initializing the joint: I am passing the joint pivot, the body tied to the joint and the point of intersection. You can see the (8.5,6.5) is the same as pivot’s origin (line 43).

Line 58: Adding the joint to the world.

And that’s it. Believe me, Box2D is very easy once you know the basics.

And this is the source code for you to download.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (12 votes, average: 4.83 out of 5)
Loading ... Loading ...
Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 14 comments

  1. Niall Lavigne

    on January 13, 2009 at 8:32 pm

    PLEASE make the colours a bit darker, I could hardly see the last few box2d tutorials you’ve made. It looks pretty cool but I can’t really tell D:

  2. Shival

    on January 14, 2009 at 6:36 am

    “Once you know the basics…”

    Where do we learn the basics?

  3. X-Tender

    on January 14, 2009 at 11:04 am

    Nice. Could you do something with Sensors? I have problems to understnad ist :)

  4. thivy

    on January 14, 2009 at 1:24 pm

    Hey man thanks heaps for you tuts
    i am just getting into box2d this is my new work with box2d
    http://www.thivy.com

  5. Box2D joints: Revolute Joint - Building motors : Emanuele Feronato

    on January 19, 2009 at 2:11 pm

    [...] seeing how to create a revolute joint, it’s time to use them to create [...]

  6. Creating a sling with Box2D using joints : Emanuele Feronato

    on February 7, 2009 at 10:43 pm

    [...] used a distance joint, a revolute joint and a motor. The code does not need to be commented because there is nothing new, just look how I [...]

  7. Box2D joints: Gear Joints : Emanuele Feronato

    on February 14, 2009 at 12:56 am

    [...] other kinds of joint, the gear joint requires you have two bodies connected to ground by a revolute or prismatic [...]

  8. Manjil Pote

    on March 17, 2009 at 7:27 am

    I got it so hard and complicated, very hard to understand.

  9. Two ways to make Box2D cars : Emanuele Feronato

    on April 6, 2009 at 12:45 pm

    [...] truck is made using various joints, such as revolute joints and prismatic [...]

  10. Basic Box2D rope : Emanuele Feronato

    on October 5, 2009 at 11:07 pm

    [...] link is (guess what?) linked to the previous one with a revolute joint. Refer to Box2D joints: Revolute Joint if you need more information about revolute [...]

  11. Zas

    on January 12, 2010 at 1:57 am

    Hello,

    how did you make it that the objects rotation slows down after a while?

    http://www.box2d.org/forum/viewtopic.php?f=4&t=4264&p=20404

  12. Box2DFlash 2.1a released – what changed : Emanuele Feronato - italian geek and PROgrammer

    on January 27, 2010 at 5:21 pm

    [...] words, so I created a simple vehicle you can control with left and right arrow keys. It uses revolute joints and [...]

  13. Emanuele Feronato - italian geek and PROgrammer

    on April 11, 2010 at 2:25 pm

    [...] and uncommented code, but a lot of useful information about compound objects, revolute joints and [...]

  14. jaydn

    on December 8, 2011 at 6:05 am

    Emanuele, it would be nice to see how to implement a rubber band with box2d