Skip to content

Commit

Permalink
Closed app with ESC button in linux project.
Browse files Browse the repository at this point in the history
  • Loading branch information
Virako committed May 7, 2015
1 parent 4e23586 commit 43fd29e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Classes/GameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


#include "GameScene.h"
#include "IntroScene.h"
#include <iostream>
#include <cmath>

Expand Down Expand Up @@ -49,6 +50,10 @@ bool gravity::GameScene::init()
listener->onTouchEnded = CC_CALLBACK_2(gravity::GameScene::onTouchEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

auto keyListener = EventListenerKeyboard::create();
keyListener->onKeyPressed = CC_CALLBACK_2(gravity::GameScene::onKeyPressed, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(keyListener, this);

Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();

Expand Down Expand Up @@ -262,6 +267,15 @@ void gravity::GameScene::onTouchEnded(Touch* touch, Event *event)
_me->runAction(RotateTo::create(0.5f, angle));
}

void gravity::GameScene::onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event *event)
{
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
{
auto intro = IntroScene::createScene();
Director::getInstance()->replaceScene(TransitionFade::create(0.5, intro, Color3B(0,0,0)));
}
}

void gravity::GameScene::explosion(Sprite *other)
{
ParticleSystemQuad *emitter = ParticleSystemQuad::create("ExplodingRing.plist");
Expand Down
1 change: 1 addition & 0 deletions Classes/GameScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class GameScene : public cocos2d::Layer

bool onTouchBegan(Touch* touch, Event *event);
void onTouchEnded(Touch* touch, Event *event);
void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event *event);
void update(float dt);
void removeOther(Sprite *sender);
void explosion(Sprite *sender);
Expand Down
11 changes: 11 additions & 0 deletions Classes/IntroScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ bool gravity::IntroScene::init()
listener->onTouchEnded = CC_CALLBACK_2(gravity::IntroScene::onTouchEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

auto keyListener = EventListenerKeyboard::create();
keyListener->onKeyPressed = CC_CALLBACK_2(gravity::IntroScene::onKeyPressed, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(keyListener, this);

Size visibleSize = Director::getInstance()->getVisibleSize();

_wadobo = Sprite::create("wadobo-games.png");
Expand Down Expand Up @@ -91,3 +95,10 @@ void gravity::IntroScene::onTouchEnded(Touch* touch, Event *event)
auto game = GameScene::createScene();
Director::getInstance()->replaceScene(TransitionFade::create(0.5, game, Color3B(0,0,0)));
}
void gravity::IntroScene::onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event *event)
{
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
{
exit(0);
}
}
1 change: 1 addition & 0 deletions Classes/IntroScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class IntroScene : public cocos2d::Layer

bool onTouchBegan(Touch* touch, Event *event);
void onTouchEnded(Touch* touch, Event *event);
void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event *event);
};

}
Expand Down

0 comments on commit 43fd29e

Please sign in to comment.