一、引言
游戏状态层在整个游戏的过程当中,扮演了一个非常重要的角色,它的主要职责是根据游戏所处的不同阶段,来显示相应的画面。二、状态层的三种状态:
1、游戏准备状态,主要是显示游戏准备的画面2、游戏进行状态
3、游戏结束状态
三、不同状态的具体显示:
与三种状态相对应的处理函数分别是void onGameStart();
void onGamePlaying(int score);
void onGameEnd(int curScore, int bestScore);
1、OnGameStart()
在游戏开始的时候,显示游戏开始状态画面
void StatusLayer::onGameStart(){
this->showStartStatus();
}
2、onGamePlaying
游戏进行过程中,状态层主要负责显示实时得分
void StatusLayer::onGamePlaying(int score){
this->removeChild(scoreSprite);
this->scoreSprite = (Sprite* )Number::getInstance()->convert(NUMBER_FONT.c_str(), score);
scoreSprite->setPosition(Point(this->originPoint.x + this->visibleSize.width / 2,this->originPoint.y + this->visibleSize.height *5/6));
this->addChild(scoreSprite);
}
3、onGameEnd
在游戏结束的时候,需要显示游戏结束画面,在这个过程当中,包括一些动画的显示,菜单的显示等等。
void StatusLayer::onGameEnd(int curScore, int bestScore){
this->showOverStatus(curScore,bestScore);
}
具体showOverStatus的代码比较长,这里就不贴了,还请参考源码进行阅读