box2D simulation doesn't work

Posted by shadow_of__soul on Game Development See other posts from Game Development or by shadow_of__soul
Published on 2012-12-11T03:23:13Z Indexed on 2012/12/11 5:20 UTC
Read the original article Hit count: 600

has been a while since last time i used box2D, and i needed to make some stuff, and i saw that my simulation don't worked (compiles, but do anything). i haven't been able to even have working the examples or this simple example i'm pasting below:

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import Box2D.Common.Math.b2Vec2;
    import Box2D.Dynamics.b2World;
    import Box2D.Dynamics.b2BodyDef;
    import Box2D.Dynamics.b2Body;
    import Box2D.Collision.Shapes.b2CircleShape;
    import Box2D.Dynamics.b2Fixture;
    import Box2D.Dynamics.b2FixtureDef;
    import org.flashdevelop.utils.FlashConnect;
    import flash.events.TimerEvent;
    import flash.utils.Timer;

    public class Main extends Sprite
    {
        public var world:b2World;
        public var wheelBody:b2Body;
        public var stepTimer:Timer;
        public function Main():void
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            var gravity:b2Vec2 = new b2Vec2(0, 10);
            world = new b2World(gravity, true);
            var wheelBodyDef:b2BodyDef = new b2BodyDef();
            wheelBodyDef.type = b2Body.b2_dynamicBody;
            wheelBody = world.CreateBody(wheelBodyDef);
            var circleShape:b2CircleShape = new b2CircleShape(5);
            var wheelFixtureDef:b2FixtureDef = new b2FixtureDef();
            wheelFixtureDef.shape = circleShape;
            var wheelFixture:b2Fixture = wheelBody.CreateFixture(wheelFixtureDef);

            stepTimer = new Timer(0.025 * 1000);
            stepTimer.addEventListener(TimerEvent.TIMER, onTick);
            FlashConnect.trace(wheelBody.GetPosition().x, wheelBody.GetPosition().y);
            stepTimer.start();
            // entry point
        }
        private function onTick(a_event:TimerEvent):void
        {
            world.Step(0.025, 10, 10);
            FlashConnect.trace(wheelBody.GetPosition().x, wheelBody.GetPosition().y);
        }
    }
}

on this, the object should fall down, but the positions reported me by the trace method, are always 0. so is not a display problem, that i see everything freeze, is why the simulation is not working, and i have no idea why :( can anyone point me to the right direction of where i need to look for the problem?

my settings are:

windows 7 flashdevelop 4.2.1 SDK: 4.6.0 compiling for flash 10, but i tried every target i have available (till flash 11.5) project set at 30fps

© Game Development or respective owner

Related posts about flash

Related posts about box2d