Physics update problem

Hi, i’m starting to develop a physics-based game. I already encountered a problem, my scene seems to not update the physics world automatically.
Here’s my code
http://pastebin.com/wWCGA2FA AppDelegate.cpp
http://pastebin.com/G21Gdyqq Menu.cpp
This is pretty basic, but spriteSfera does not move. I analyzed the stack with gdb, the physics engine works but the forces applied don’t move the body.
Am i missing something? I tried to stick very close to the various tutorials i found
Thank you

Bumping the topic

It’s really hard to say what actually is wrong, but this simple code works for me ( i just hacked in some quick code to try this on default project template). From your implementation I noticed you use initWithPhysics, which is deprecated ( i did this with 3.2 version)

Scene* HelloWorld::createScene()
{
    auto scene = Scene::createWithPhysics();

    auto layer = HelloWorld::create();
    layer->m_world = scene->getPhysicsWorld();
    scene->addChild(layer);    
    return scene;
}

 bool HelloWorld::init()
 {
     if ( !Layer::init() )
     {
         return false;
     }

    scheduleUpdate();
    return true;
}

void HelloWorld::initPhysics()
{
    m_world->setGravity(Vect(0.0f, -5.0f));
    m_world->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
    PhysicsMaterial mat = PhysicsMaterial(1, 1, 0);

    auto body = PhysicsBody::createCircle(1.0f, mat);
    auto sprite = Sprite::create("HelloWorld.png");
    sprite->setPhysicsBody(body);
    sprite->setPosition(200.0f, 200.0f);
    addChild(sprite);
    
}


void HelloWorld::update(float dt)
{
    static bool intialized = false;
    if(!intialized)
    {
        initPhysics();
        intialized = true;
    }
    
}

if you look at the Physics examples in CPP-Tests they all work. KJS’s example seems appropriate too.

I use your code at my project( only changed the png path ), it works for me…

Good to hear! I recommend you fix the hacks in my code, I just did quickly something that works. For example initialising the physics at first update is not good way to do it, rather do it at onEntry as in the examples. But you can use my code as a starting point.

Ok, i think i found the problem with my code.
Apparently in void ScenaMenu::update(float dt) i have to call the static method Scene::update(), because i’m overriding it. You don’t do it in your code, i guess because in init() you call scheduleUpdate(), but strangely if i do it too, it triggers a SIGSEGV at that point

In my code, Helloworld is not a Scene, it’s a Layer. Creating a scene with createWithPhysics schedules a update already for it. If you are scheduling it again, it might be the source of that error.

Good point KJS, it is a Layer

Ok, putting it together i don’t have to call scheduleUpdate() because it is called automatically with createWithPhysics. But i overridden update(), so the default one is not executed.
Many thanks guys, you rock!