Simplify your Box2D projects with QuickBox2D

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.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (17 votes, average: 4.06 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.
» 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.

19 Responses to “Simplify your Box2D projects with QuickBox2D”

  1. walrus92 on August 25th, 2009 6:29 pm

    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

  2. walrus92 on August 25th, 2009 6:29 pm

    *wall*

  3. New on August 25th, 2009 7:20 pm

    Is that really box2d, it’s more like a buggy ASphysics engine… The collision angles are way off sometimes.

  4. manoj sahu on August 25th, 2009 7:45 pm

    line #16: var ball:QuickObject=qb.addCircle({x:3,y:3,restitution:0.9,lineAlpha:1,fillColor:0×00ff00,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.

  5. matakukos on August 25th, 2009 8:38 pm

    +1

  6. Monkios on August 25th, 2009 8:59 pm

    More like always buggy …

    Nice Ebonny ads btw.

  7. Stelimar on August 25th, 2009 9:42 pm

    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.

  8. Astro75 on August 25th, 2009 10:36 pm

    I have made a similar library. Only mine is smaller and not full. http://www.box2d.org/forum/viewtopic.php?t=3101

  9. Bindriy on August 26th, 2009 2:16 am

    ????box2d????

  10. abhilash on August 26th, 2009 6:48 pm

    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?

  11. abhilash on August 26th, 2009 6:55 pm

    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

  12. abhilash on August 27th, 2009 1:49 pm

    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’ ;)

  13. Wyatt on August 27th, 2009 5:19 pm

    - 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. :)

  14. Astro75 on August 28th, 2009 4:19 pm

    If this QuickBox2d doesn’t work for you then try this http://www.box2d.org/forum/viewtopic.php?t=3101

  15. shabasky on August 31st, 2009 12:22 am

    Could someone show me how to setup QuickBox2d??? like what to download and which folders go where and what do i need?

  16. Xodus on August 31st, 2009 1:56 pm

    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!

  17. Zevan on September 11th, 2009 12:24 am

    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

  18. TimeFuzz on November 4th, 2009 2:43 pm

    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

  19. pretorian on January 11th, 2010 11:43 am

    how can i destroy QuickBox2D stageWalls?

Leave a Reply




flash games company