0

I am new to cocos2d-x and i am developing a game using cocos2d-x in x-code and in my game scene i have a player sprite and obstacle sprites. Player sprite is running on the same place and obstacle sprites are moving from right to left of the scene. After the inclusion of obstacle sprites my scene FPS is keep on decreasing from 50 to below 10. And i am using the following code to add my obstacle sprites. I am assigning the tag to obstacles for collision detection.

bool init()
{
 time=1;
 schedule( schedule_selector(playscene::spritemovefinished));



void PlayScene::OnObstacle()
{
 time=time+1;
 i=arcrandom()%9;

obs1->setPosition(ccp((winwsize/5)+(2*winwsize),winhsize/2.45));
this->addChild(obs1,1);
obs1->setVisible(true);

obs1->setTag(2);
_obs1->addObject(obs1);


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

obs2->setTag(2);
_obs2->addObject(obs2);

if(time%60==0&&i>=0&&i<=1)
{
    CCFiniteTimeAction* act1=CCMoveTo::create(7.0,ccp(-50,winhsize/2.45));
    CCFiniteTimeAction*    act1end=CCCallFuncN::create(this,callfuncN_selector(PlayScene::spriteMoveFinished));
    obs1->runAction(CCSequence::create(act1,act1end,NULL));
    CCRotateBy *rot=CCRotateBy::create(13, -2000);
    obs1->runAction(rot);

}
else if(time%60==0&&i>1&&i<=2)
{
    CCFiniteTimeAction* act2=CCMoveTo::create(7.0,ccp(-50,winhsize/2.45));
    CCFiniteTimeAction* act2end=CCCallFuncN::create(this,callfuncN_selector(PlayScene::spriteMoveFinished));
    obs2->runAction(CCSequence::create(act2,act2end,NULL));
    CCRotateBy *rot1=CCRotateBy::create(13, -2000);
    obs2->runAction(rot1);    
}
}
void PlayScene::spritemovefinished(CCNODE* sender)
{
   CCSprite *sprite = (CCSprite *)sender;
   this->removeChild(sprite, true);
}     
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
socrates
  • 124
  • 10
  • As you give the program more work to do, it takes longer for it to do it. This should be expected. Did you have some reason to think it wouldn't, or at least expect some minimum FPS? – Scott Hunter May 14 '14 at 13:57
  • There is a [GameDev StackExchange site](http://gamedev.stackexchange.com/), you could try there if you can't find an answer here. – jspurim May 14 '14 at 14:04
  • How many obstacles are you adding? Does the framerate decrease over time or is it steady with the same number of obstacles? – molbdnilo May 14 '14 at 14:07
  • totally eight obstacles – socrates May 14 '14 at 14:07
  • @socrates You shouldn't even notice eight on a modedrn machine. Make sure you're not doing too much work (collision detection, etc) per obstacle. – molbdnilo May 14 '14 at 14:10
  • framerate is decrease from 50 to below 10.once it reaches below 10 it stays and never got increase. – socrates May 14 '14 at 14:10
  • I added eight obstacles and make collision with player sprite. If it collide with player sprite then the game got over. – socrates May 14 '14 at 14:14
  • 1
    Please don't repost essentially the same question (http://stackoverflow.com/questions/23647035/decreasing-fps-while-adding-obstacles). What device are you testing this on? If it's the simulator the performance measurement is pretty much null and void. – CodeSmile May 14 '14 at 14:27
  • I am using it in ios simulator and also in android device but its not working in any of it.I didn't repost this question. – socrates May 14 '14 at 14:40
  • 1
    @socrates - you are essentially bombarding SO with duplicates. Look at your question history. You post multiple times essentially the exact same issue. Give us a change to answer you! You cannot trust simulators to give you accurate #'s you need to test on hardware. Example. I have a game that uses threads and in the simulator these threads run behind. When I run on hardware everything is spot on. – GameDeveloper May 14 '14 at 15:12

0 Answers0