Fps is slow down to 1 if i create 1000 physics body

Fps is slow down to 1 if i create 1000 physics body
0.0 0

#1

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


#2

please share some code to look into it.


#3

I have a game with at least 1000 physics bodies on the screen at once. I’m still at 60fps. Please share code


#4

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());

  }

#5

mostly problem in android device


#6
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());

  }

#7

What device are you testing on? Actual hardware or using an emulator? What cocos2d-x version?


#8

cocos2dx 3.16 and

  1. android samsung (galaxy A5), model no : SM-A500g, Android version 6.0.1
  2. android samsung (galaxy S4) model no: GT-I9500 , Android version 5.0.1

#9

is there any solution for this issue ?


#10

I don’t see this on an HTC Nexus 9. I made 10,000+ nodes and my performance was great.