Hi all,
I am using cocos2dx 3.10. I am trying to make a ball moving around a Edgebox but everytime I increate velocity or applying a big force, the ball will easy pass through the edgebox. I tried to manually set step in update(dt) function but my game is always crashed at that line with error EXEC_BAD_ACCESS. Below is my code. Should I move to Box2d?
Scene* GameScene::scene(int lvlIndex)
{
// ‘scene’ is an autorelease object
// auto scene = Scene::create();
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
//
scene->getPhysicsWorld()->setSpeed(0.06f);
scene->getPhysicsWorld()->setAutoStep(false);
// 'layer' is an autorelease object
auto layer = GameScene::create();
layer->physicsWorld = scene->getPhysicsWorld();
// add layer as a child to scene
scene->addChild(layer);
return scene;
}
//
//Init ball
ball1 = Sprite::create("ball_11.png");
ball1->setPosition(Point(500, 200));
auto spriteBody = PhysicsBody::createCircle(ball1->getContentSize().width/2);
spriteBody->getShape(0)->setRestitution(1.0f);
spriteBody->getShape(0)->setFriction(0.0f);
spriteBody->getShape(0)->setDensity(.0f);
spriteBody->setContactTestBitmask(0x1);
spriteBody->setGravityEnable(false);
ball1->setPhysicsBody(spriteBody);
this->addChild(ball1);
//
//Update
void GameScene::loop(float dt)
{
CCLOG(“Loopping is here …%f”,dt);
this->getScene()->getPhysicsWorld()->step(dt); //Crashed here
}