if create 1000 body at same time game is hang and fps is slow down to 1.
i want to make game like https://play.google.com/store/apps/details?id=com.crater.bbtan
please share some code to look into it.
I have a game with at least 1000 physics bodies on the screen at once. I’m still at 60fps. Please share code
for(int i=0;i<1000;i++)
{
auto ball = Sprite::create("ball.png");
ball->setPosition(prevLastBallPostion);
ball->setScaleX(PosX);
ball->setScaleY(PosX);
PhysicsBody *ballBody = PhysicsBody::createCircle((ball->getContentSize().width*0.5f)*PosX);
ballBody->setTag(1000);
ballBody->getShape(0)->setRestitution(1.0f);
ballBody->getShape(0)->setFriction(0.0f);
ballBody->getShape(0)->setDensity(1.0f);
ballBody->setGravityEnable(false);
ballBody->setCategoryBitmask(0x02);
ballBody->setContactTestBitmask(0x01|0x08);
ballBody->setCollisionBitmask(0x01|0x08);
ballBody->setMoment(PHYSICS_INFINITY);
ball->setPhysicsBody(ballBody);
ballBody->setMass(300);
this->addChild(ball,101);
// log("%f",ballBody->getMass());
}
mostly problem in android device
for(int i=0;i<1000;i++)
{
auto ball = Sprite::create("ball.png");
ball->setPosition(prevLastBallPostion);
ball->setScaleX(PosX);
ball->setScaleY(PosX);
PhysicsBody *ballBody = PhysicsBody::createCircle((ball->getContentSize().width*0.5f)*PosX);
ballBody->setTag(1000);
ballBody->getShape(0)->setRestitution(1.0f);
ballBody->getShape(0)->setFriction(0.0f);
ballBody->getShape(0)->setDensity(1.0f);
ballBody->setGravityEnable(false);
ballBody->setCategoryBitmask(0x02);
ballBody->setContactTestBitmask(0x01|0x08);
ballBody->setCollisionBitmask(0x01|0x08);
ballBody->setMoment(PHYSICS_INFINITY);
ball->setPhysicsBody(ballBody);
ballBody->setMass(300);
this->addChild(ball,101);
// log("%f",ballBody->getMass());
}
What device are you testing on? Actual hardware or using an emulator? What cocos2d-x version?
cocos2dx 3.16 and
- android samsung (galaxy A5), model no : SM-A500g, Android version 6.0.1
- android samsung (galaxy S4) model no: GT-I9500 , Android version 5.0.1
is there any solution for this issue ?