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