添加多个障碍会导致FPS降低

时间:2014-05-14 13:52:42

标签: c++ cocos2d-x

我是cocos2d-x的新手,我在x-code中使用cocos2d-x开发游戏,在我的游戏场景中,我有一个玩家精灵和障碍精灵。玩家精灵在同一个地方运行,障碍物精灵从场景的右侧移动到左侧。在包含障碍物精灵之后,我的场景FPS继续从50减少到10以下。我使用以下代码添加我的障碍精灵。我正在为碰撞检测的障碍物分配标签。

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

0 个答案:

没有答案