I've been using box2d lately and managed to pull off an angry birds like trial with the walls and the projectile but the problem i can't seem to solve is creating custom shapes. I've managed to use boxes for the polygon shape of the walls and other objects and circle for the shape of the ball but i can't seem to make custom shapes like triangles or even complex shapes like forming a flag or a spike or something else.
I've read through the net and can't seem to understand and implement some samples i've found. Oh and i'm using the physics helper from
http://www.giderosmobile.com/forum/discussion/373/display-object-physics-helper-library
Comments
http://appcodingeasy.com/Gideros-Mobile/Creating-terrain-in-Gideros-using-ChainShape
But it mostly can be used as terrain (box2d limitation) and can not be dynamic.
If you want a dynamic complex shape, then you need b2.EdgeShape. But it also has its own (box2d) limitations. I think it can only have up to 8 vertices and they should be defined clockwise order.
If you need dynamic shape which should have more than 8 vertices, you will need to create a body of multiple b2.EdgeShape fixtures
But I think that all the physics editors, like physics helper, should automatically convert the drawn shape to the best code case.
Do you have a tutorial on edgeshapes? I mean even just a small piece of code which shows how to define the shape.
Here's a simple code:
Is the x and y of the shape based on the object or is it based on the x and y of the whole stage? Like if i have a sprite on 300,550, do i have to base the shape from that location or what?
Edit: Ok, i've tried to add some things to the helper and came up with this
next up is collisions and the only samples i've seen so far are all collisions within the body and not the edges only -,-. study study haha
Collisions are working fine now and i'm getting the intended collision output except when i'm trying to remove a body on collision. I keep getting an error saying "world is locked" how do i unlock the world?
Edit: ok i've found a way around. I set the world:step to (0,0,0) just before removing the bodies and it worked nicely. Is this a safe move? i mean sometimes the player suddenly hangs and must be closed randomly when a collision is made
To ensure proper simulation of physics values passed to world:step should always be the same.
The world lock notice is given due to the fact you are removing a body in the same enterFrame event where you received collision.
Most quick and dirty hack is to remove the body using a Timer delay, like:
right now i'm having problem with collisions in implementing an out-of-bounds for the object. I'll ask if ever i hit a dead end. Thanks again, you're a big help
edit: scratch that, found the dead end already. I've been trying to destroy the body of the ball object that makes contact with the boundaries i've made and when i try to destroy the ball body, it says "Body is already destroyed" I've tried resorting to just moving the ball object and it's body back to it's original place but doesn't work either. The force applied to the ball just as it made contact with the boundary is still applied to it. Is there a work around this?
right now i have a collision detector