0

I am new to cocos2d-x and I am developing a game in x-code using cocos2d-x.In my game i have a menu scene and game scene. In my game scene after adding the obstacles FPS is decreasing to 10 So my game performance is very low. Following is the code which i used to add obstacles in my game. and i have eight obstacles in my game. I created all the obstacles in one function and call that function by scheduler from init().Please help me solve this problem.

 time = time + 1;
int i=arc4random()%9;

obs1 = CCSprite::create("obs1.png");
obs1->setPosition(ccp((winwsize/5)+(2*winwsize),winhsize/2.45));
this->addChild(obs1,1);
obs1->setVisible(true);

  if(time%60==0&&i>=0&&i<=1)
{
    CCActionInterval* act1=CCMoveTo::create(7.0,ccp(-50,winhsize/2.45));
    obs1->runAction(CCRepeatForever::create(act1));
    CCRotateBy *rot=CCRotateBy::create(13, -2000);
    obs1->runAction(rot);
}
socrates
  • 124
  • 10
  • Is it slowing down when you create the objects or when you're rendering them? – PomfCaster May 14 '14 at 06:34
  • thanks for your comment. Using the above code I added the obstacles sprite and move it from right to left on the game scene. after added this obstacle sprites my game scene FPS got slow down to 10. So want to know why FPS got down after added the obstacle sprites. Whether the way I created the obstacle is wrong or After added the child to the sprite I need remove it. – socrates May 14 '14 at 06:41
  • 1
    It doesn't sound like adding the object is causing your FPS to go down, but instead because you're now drawing more objects your FPS is going down. – PomfCaster May 14 '14 at 06:45
  • Are all this code in a update function (it sets by layer schedule function)? – Salvatore Avanzo May 14 '14 at 07:04
  • All these codes are in the function name called obstacle and call that function from init() function by the following code schedule(schedule_selector(PlayScene::Obstacle)); – socrates May 14 '14 at 07:20
  • 10 fps on what device? Try using CCspriteBatchNode for the sprites. – CodeSmile May 14 '14 at 07:38
  • I hope this will be very helpful for you check it here. [FPS Drop Never Recovers][1] [1]: http://stackoverflow.com/questions/19513364/cocos2dx-2-1-4-game-continuos-fps-drop-and-never-recovers/19519000#19519000 – Deva May 14 '14 at 07:50

0 Answers0