Creation of a Flash Stabilize! clone using Box2D – part 2

Time to add some new features to our Stabilize! clone we started in this post.

The features we’ll add this time are:

* Restricted area in which you can drop crates
* “Real” crates, made with a movieclip, take the place of the boxes you can draw with the mouse

As you can see, the script looks less and less like the original Drawing boxes on the fly in Box2D and it’s starting to become a custom one.

To create the restricted area, I simply create the area movieclip and check if the mouse in inside such movieclip with hitTestPoint method.

It works with three parameters:

x:Number – The x coordinate to test against this object.

y:Number -The y coordinate to test against this object. These coordinates are mouseX and mouseY

shapeFlag:Boolean (default = false) -Whether to check against the actual pixels of the object (true) or the bounding box (false). Obviously I want it to be true

Here it is the source code:

And this is the result:

Click inside the red area to drop a crate

Download the source code, Box2D library excluded

  • Thanks, really simple and straight forward.
    Note the you don’t have to create movieclips, you can define range of X and Y and in every click check if the X and Y of the mouse are in it, it will be better practice in my opinion.

  • Emanuele Feronato

    I disagree, because if I want to provide some visual hint on the droppable area, I have to use a MC.

    Moreover, with your method is not possible to detect regular drops if you want your droppable area to have a shape of a star, an elephant, and so on

  • Guest

    Emanuele, maybe this: http://jobemakar.blogspot.com/2009/10/simple-spring-experimentation.html can be used as a guide to create a realistic rope?…

  • Vadersapien

    Looks like your site’s been hacked again…firefox gives me this whenever I visit it: “This web page at http://www.emanueleferonato.com has been reported as an attack page and has been blocked based on your security preferences.”

    Also the pages are text-only.

  • Yeah i get the same message

  • Emanuele Feronato

    yes, I am changing hosting service, should be fixed soon.

    thank you