-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAbout.cpp
61 lines (52 loc) · 1.56 KB
/
About.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "About.h"
#include "HelloWorldScene.h"
USING_NS_CC;
Scene* GameAbout::createScene()
{
auto scene = Scene::create();
auto layer = GameAbout::create();
scene->addChild(layer);
return scene;
}
bool GameAbout::init()
{
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
//背景
auto sprite = Sprite::create("about/aboutui.png");
sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(sprite);
//响应键盘消息
auto keyListener = EventListenerKeyboard::create();
keyListener->onKeyReleased = CC_CALLBACK_2(GameAbout::onKeyReleased, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
//可以触控
this->setTouchEnabled(true);
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(GameAbout::onTouchBegan, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
return true;
}
//返回主界面
void GameAbout::onKeyReleased(EventKeyboard::KeyCode keycode,Event* event)
{
if(keycode == EventKeyboard::KeyCode::KEY_BACKSPACE)
{
/*Scene* newScene = HelloWorld::createScene();
HelloWorld* layer = HelloWorld::create();
newScene->addChild(layer);
Director::sharedDirector()->pushScene(newScene);*/
Director::sharedDirector()->popScene();
}
}
//响应触摸
bool GameAbout::onTouchBegan(Touch *touch, Event *unused)
{
CCLOG("here");
Director::sharedDirector()->popScene();
return false;
}