游戏结束层:EndLayer

游戏结束层带有两个参数,第一个参数是是否成功,第二个参数完成百分比

Scene * EndLayer::createScene(bool isWin, int percent){
auto scene = Scene::create();
EndLayer *layer = new EndLayer( isWin, percent);
scene->addChild(layer);
return scene;
}
无论游戏成功失败都有返回选关主界面的菜单按钮

//创建菜单
auto *menu = Menu::create();
menu->setPosition(zeroPos);
//返回选关主界面
auto * menuCheckPoint = MenuItemSprite::create(Sprite::createWithSpriteFrameName("menuNormal.png"), Sprite::createWithSpriteFrameName("menuPress.png")
, CC_CALLBACK_1(EndLayer::menu, this));
menuCheckPoint->setTag(menuTag);
menuCheckPoint->setPosition(Point(centerPos.x - menuCheckPoint->getContentSize().width / 2, size.height / 3));
menuCheckPoint->setScale(0.7);
menu->addChild(menuCheckPoint);
区别在于成功是下一关按钮,失败是重新开始按钮

if (isWin){
//胜利了而且不是最后一关 显示下一关按钮
if (checkPoint != CHECK_POINT_NUM){
auto * menuCheckPoint = MenuItemSprite::create(Sprite::createWithSpriteFrameName("nextNormal.png"), Sprite::createWithSpriteFrameName("nextPress.png")
, CC_CALLBACK_1(EndLayer::next, this));
menuCheckPoint->setTag(nextTag);
menuCheckPoint->setPosition(Point(centerPos.x + menuCheckPoint->getContentSize().width / 2, size.height / 3));
menuCheckPoint->setScale(0.7);
menu->addChild(menuCheckPoint);
}

}
else{
//失败了 显示重新开始按钮
auto * menuCheckPoint = MenuItemSprite::create(Sprite::createWithSpriteFrameName("reStartNormal.png"), Sprite::createWithSpriteFrameName("reStartPress.png")
, CC_CALLBACK_1(EndLayer::restart, this));
menuCheckPoint->setTag(restartTag);
menuCheckPoint->setPosition(Point(centerPos.x + menuCheckPoint->getContentSize().width / 2, size.height / 3));
menuCheckPoint->setScale(0.7);
menu->addChild(menuCheckPoint);
}
剩下的就是精灵图层,完成百分比,提示语信息

项目托管在github:https://github.com/smiger/ParkourBall