Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17064

PhysicsWorld is not working

$
0
0

Hi everyone! I’m trying to use physics in cocos2d-x but it doesn’t work. I want to reproduce part of example from manual. Here is my init() code:

    if (!Scene::initWithPhysics())
        return false;

    getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

    auto visibleSize { Director::getInstance()->getVisibleSize() };
    Point screenCenter { visibleSize.width/2, visibleSize.height/2 };

    auto square { Sprite::create("square.png") };
    auto physicsBody { PhysicsBody::createBox(square->getContentSize(), PhysicsMaterial(0.1f, 1.0f, 0.0f)) };

    physicsBody->setGravityEnable(false);
    physicsBody->setVelocity(Vec2(cocos2d::random(-500,500), cocos2d::random(-500,500)));
    physicsBody->setTag(10);

    square->setPosition({screenCenter.x, screenCenter.y});
    square->addComponent(physicsBody);
    addChild(square);

    return true;

However, I get a static object as if I were creating a normal sprite. It doesn’t even show a red debug mark around it. getPhysicsWorld()->getAllBodies().size() gives me 0. Also I tried to create EdgeBox but got same problem.


I’m using Linux, compile with gcc 10.2.0, cocos2d-x 4.0 (also tried with 3.17.2). This init() code were made in automatically created HelloWorld scene in new project. I had problems with chipmunk (undefined reference to `__powf_finite') so I built libchipmunk with -fno-builtin flag and replace prebuilt lib with currently built. Demos in libchipmunk working without problems with new buildDemos in libchipmunk working without problems with new build, but not my code with cocos :frowning:

8 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 17064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>