Simplify your Box2D projects with QuickBox2D
- August 25, 2009 by Emanuele Feronato
- Filed under Actionscript 3, Box2D, Flash, Game design | 20 Comments
You know with Box2D you can make interesting games like Mazeroll, SamePhysics or Filler, but even if I published a Box2D tutorial for absolute beginners, everyday I am receiving emails complaining about the excessive complexity of this library.
If you are looking for a library able to simplify your Box2D projects, Zevan Rosser from ActionSnippet developed a library called QuickBox2D that promises to significantly simplify instantiation of rigid bodies and provide a simple way to skin rigid bodies with custom graphics.
In this quick example I am going to add a sphere to the stage and make it draggable.
Before looking at this script, take a look at Dragging objects with Box2D Flash to see how many lines of code I needed to make those crates draggable.
This is what you need with QuickBox2D:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | package { import flash.display.MovieClip; // importing required library import com.actionsnippet.qbox.*; // it must be a MovieClip!! With a Sprite it won't work! public class quickbox extends MovieClip { public function quickbox() { // setting up the QuickBox2D world var qb:QuickBox2D=new QuickBox2D(this); // default fill color qb.setDefault({lineAlpha:0, fillColor:0xff0000}); // automatic stage walls creation!!!!!!! qb.createStageWalls(); // adding a ball... that easy... var ball:QuickObject=qb.addCircle({x:3,y:3,restitution:0.9,lineAlpha:1,fillColor:0x00ff00,allowSleep:false,fixedRotation:true}); // automatic mouse dragging!!! qb.mouseDrag(); // starting the simulation qb.start(); } } } |
and this is what you get…
And this is the source code with all libraries in the correct path.
They can be easily customized to meet the unique requirements of your project.
20 Responses
Leave a Reply
TUTORIAL SERIES:
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online

(18 votes, average: 4.11 out of 5)

Very nice, but one thing I noticed about this was that when you throw the ball at an angle towards the floor, ceiling, or floor, that it stops following that angle and starts to bounce perpendicularly
*wall*
Is that really box2d, it’s more like a buggy ASphysics engine… The collision angles are way off sometimes.
line #16: var ball:QuickObject=qb.addCircle({x:3,y:3,restitution:0.9,lineAlpha:1,fillColor:0x00ff00,allowSleep:false,fixedRotation:true});
what is restitution:0.9? never found such property in any kind of PL,i wonder how guys are going against simplicity?.PL and library are about to make make programmers life easier rather then dumb.
+1
More like always buggy …
Nice Ebonny ads btw.
Looking at the code, objects automatically have a friction of 0.5, which might be why the ball seems to bounce weird. I’d try setting it lower, to maybe 0.2 or 0.3.
Anyways, nice post. I’ve heard of this library before, but never taken the time to try to figure it out.
I have made a similar library. Only mine is smaller and not full. http://www.box2d.org/forum/viewtopic.php?t=3101
????box2d????
gr8 it is the first physics engine of which each and every line i can understand looks really simple btw when are u writing next part of BOX2d for beginners?
dunno why but after following your Box2d for beginners steps for this engine i can’t seem to get it work when i compile the movie it says
5008: The name of definition ‘quickbox’ does not reflect the location of this file. Please change the definition’s name inside this file, or rename the file. D:\Abhilash files(july)\Quick Box\demo.as
aaah!!tried each every trick to make it work but still it’s giving errors, i think it’s time for you to write ‘QuickBox2d for absolute
beginners’ ;)
- abhilash:
Perhaps you should rename the “demo.as” file as “quickbox.as” or change “public class quickbox” to “public class demo” and “public function quickbox()” to “public function demo()”. I suggest the first one though. :)
If this QuickBox2d doesn’t work for you then try this http://www.box2d.org/forum/viewtopic.php?t=3101
Could someone show me how to setup QuickBox2d??? like what to download and which folders go where and what do i need?
It seems like there isnt any spin, when you hold up the ball, it doesnt spin around. Also, the ball doesnt roll on the ground…
Anyway, very good idea, box2d seems so much simpler!
Thanks for mentioning QuickBox2D Emanuele.
Hey Xodus… thats because Emanuele has set fixedRotation = false on the circle… I assume he has done this to show the flexibility of QuickBox2D
This library is fantastic for people without much as3 experience. However, I do have a problem/question:
Is there a way of easily resetting the simulation using quickbox2D? I have a game almost complete using the quickbox library, but now need to basically clear the screen in between the levels, but this is where I am having troubles.
I have tried qb.destroy() which should work but this only stops the simulation and all the boxes and circles are still on screen.
This is probably a really dumb and easy thing to do but I’m not the greatest at as3, so any help would really be appreciated!
Thanks
TimeFuzz
how can i destroy QuickBox2D stageWalls?
Thanks to zevan for this great enhancement.