-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pause.cpp
63 lines (44 loc) · 1.45 KB
/
Pause.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
62
63
#include "Pause.h"
#include "ui/CocosGUI.h"
Pause::Pause()
{
}
Pause::~Pause()
{
}
bool Pause::init()
{
if (Layer::init() == false) {
return false;
}
auto viewSize = Director::getInstance()->getVisibleSize();
auto background = LayerColor::create(Color4B(0, 0, 0, 200));
auto box = ui::Scale9Sprite::create("message_box.png");
auto continueBut = ui::Button::create("continue.png");
auto endGameBut = ui::Button::create("end_game.png");
box->setContentSize(Size(450, 300));
box->setPosition(viewSize.width / 2, viewSize.height / 2);
continueBut->setPosition(Vec2(viewSize.width / 2, viewSize.height / 2 + 75));
endGameBut->setPosition(Vec2(viewSize.width / 2, viewSize.height / 2 - 75));
this->setContentSize(viewSize);
this->addChild(background);
this->addChild(box);
this->addChild(continueBut);
this->addChild(endGameBut);
continueBut->addClickEventListener([this](Ref* ref){
_continueCallback();
});
endGameBut->addClickEventListener([this](Ref* ref){
_endGameCallback();
});
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch* touch, Event* event){return true; };
listener->setSwallowTouches(true);
background->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, background);
return true;
}
void Pause::registerCallback(std::function<void()> continueCallback, std::function<void()> endGameCallback)
{
_continueCallback = continueCallback;
_endGameCallback = endGameCallback;
}