-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
结束界面
- Loading branch information
Showing
3 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include "EndLayer.h" | ||
#include "GameLayer.h" | ||
#include "SimpleAudioEngine.h" | ||
#include "HelloWorldScene.h" | ||
USING_NS_CC; | ||
|
||
|
||
Scene *EndLayer::createScene() | ||
{ | ||
auto scene = Scene::create(); | ||
auto layer = EndLayer::create(); | ||
scene->addChild(layer); | ||
return scene; | ||
} | ||
|
||
bool EndLayer::init() | ||
{ | ||
if ( !Layer::init() ) | ||
{ | ||
return false; | ||
} | ||
Size visibleSize = Director::getInstance()->getVisibleSize(); | ||
Point origin = Director::getInstance()->getVisibleOrigin(); | ||
//背景初始化 | ||
end_bg= Sprite::create("main_game/bg_success.png"); | ||
end_bg->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); | ||
this->addChild(end_bg,0); | ||
//步数初始化 | ||
end_step = LabelTTF::create("step", "fonts/fzmwt.ttf", 70); | ||
end_step->setPosition(ccp(visibleSize.width/2+30,visibleSize.height/2+130)); | ||
end_step->setColor(Color3B::RED); | ||
|
||
//返回主界面按键 | ||
auto closeItem = MenuItemImage::create( | ||
"main_game/home1.png", | ||
"main_game/home2.png", | ||
CC_CALLBACK_1(EndLayer::menuCloseCallback, this)); | ||
|
||
closeItem->setPosition(ccp(-110,-200)); | ||
|
||
//重新开始按钮 | ||
auto end_retry = MenuItemImage::create( | ||
"main_game/retry1.png", | ||
"main_game/retry2.png", | ||
CC_CALLBACK_1(EndLayer::Retry, this)); | ||
end_retry->setPosition(ccp(80,-135)); | ||
|
||
//分享按钮 | ||
auto end_share = MenuItemImage::create( | ||
"main_game/share1.png", | ||
"main_game/share2.png", | ||
CC_CALLBACK_1(EndLayer::Share,this)); | ||
end_share->setPosition(ccp(-30,-155)); | ||
|
||
// create menu, it's an autorelease object | ||
auto menu = Menu::create(closeItem,end_retry,end_share,NULL); | ||
this->addChild(menu,1); | ||
|
||
//响应键盘消息 | ||
auto keyListener = EventListenerKeyboard::create(); | ||
keyListener->onKeyReleased = CC_CALLBACK_2(EndLayer::onKeyReleased, this); | ||
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this); | ||
|
||
return true; | ||
} | ||
|
||
void EndLayer::Retry(Ref* pSender) | ||
{ | ||
auto newScene = GameLayer::createScene(); | ||
CCDirector::sharedDirector()->replaceScene(newScene); | ||
} | ||
|
||
void EndLayer::Share(Ref* pSender) | ||
{ | ||
//待修改——分享 | ||
auto newScene = GameLayer::createScene(); | ||
CCDirector::sharedDirector()->replaceScene(newScene); | ||
} | ||
|
||
void EndLayer::menuCloseCallback(Ref* pSender) | ||
{ | ||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) | ||
MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); | ||
return; | ||
#endif | ||
auto newScene = HelloWorld::createScene(); | ||
CCDirector::sharedDirector()->replaceScene(CCTransitionCrossFade::create(0.3,newScene)); | ||
//Director::getInstance()->end(); | ||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) | ||
exit(0); | ||
#endif | ||
} | ||
|
||
//响应安卓返回键 | ||
void EndLayer::onKeyReleased(EventKeyboard::KeyCode keycode,Event* event) | ||
{ | ||
if(keycode == EventKeyboard::KeyCode::KEY_BACKSPACE) | ||
{ | ||
Director::sharedDirector()->replaceScene(CCTransitionCrossFade::create(0.3,HelloWorld::createScene())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef __EndLayer_H__ | ||
#define __EndLayer_H__ | ||
|
||
#include "cocos2d.h" | ||
|
||
USING_NS_CC; | ||
|
||
class EndLayer : public Layer | ||
{ | ||
public: | ||
static Scene* createScene(); | ||
CREATE_FUNC(EndLayer); | ||
bool m_isRun; | ||
int m_step; | ||
//分享按键回调函数 | ||
void Share(cocos2d::Ref* pSender); | ||
//重新开始按键回调 | ||
void Retry(cocos2d::Ref* pSender); | ||
//返回主界面回调 | ||
void menuCloseCallback(cocos2d::Ref* pSender); | ||
virtual void onKeyReleased(EventKeyboard::KeyCode keycode,Event* event)override; | ||
virtual bool init(); | ||
LabelTTF* end_step; | ||
Sprite* end_bg; | ||
}; | ||
|
||
#endif /* defined(__EndLayer_H__) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters