Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
I played around with this and got it to work - I'd suggest trying out the tutorials and seeing if you can replicate what you're looking for in a simple system. And I did find out that if you want something to fall down, you need to make Gravity negative - var gravity:b2Vec = new b2Vec2(0, -10); – Gone3d Dec 20 '12 at 21:44

closed as too localized by Byte56, Trevor Powell, Josh Petrie, bummzack, Sean Middleditch Dec 30 '12 at 5:27

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.