-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelloWorldScene.cpp
140 lines (121 loc) · 4.26 KB
/
HelloWorldScene.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "ui\UIButton.h"
#include "MyUI.h"
USING_NS_CC;
using namespace ui;
Scene* HelloWorld::createScene()
{
return HelloWorld::create();
}
// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
printf("Error while loading: %s\n", filename);
printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Scene::init() )
{
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
// auto closeItem = MenuItemImage::create(
// "CloseNormal.png",
// "CloseSelected.png",
// CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
//
// if (closeItem == nullptr ||
// closeItem->getContentSize().width <= 0 ||
// closeItem->getContentSize().height <= 0)
// {
// problemLoading("'CloseNormal.png' and 'CloseSelected.png'");
// }
// else
// {
// float x = origin.x + visibleSize.width - closeItem->getContentSize().width/2;//x軸 (現在是右下)
// float y = origin.y + closeItem->getContentSize().height/2;//y軸 (現在是右下)
// closeItem->setPosition(Vec2(x,y));
// }
//
// create menu, it's an autorelease object
// auto menu = Menu::create(closeItem, NULL);
// menu->setPosition(Vec2::ZERO);
// this->addChild(menu, 1);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
// auto title = Label::createWithTTF("Card Memory", "fonts/Chalkduster.ttf", 60);
// if (title == nullptr)
// {
// problemLoading("'fonts/Chalkduster.ttf'");
// }
// else
// {
// // position the label on the center of the screen
// title->setPosition(Vec2(origin.x + visibleSize.width / 2,
// origin.y + visibleSize.height - title->getContentSize().height - 20));
//
// // add the label as a child to this layer
// this->addChild(title, 1);
// }
// auto subtitle = Label::createWithTTF("Group 10 Produced", "fonts/Chalkduster.ttf", 14);
// if (subtitle == nullptr)
// {
// problemLoading("'fonts/Chalkduster.ttf'");
// }
// else
// {
// position the label on the center of the screen
// subtitle->setPosition(Vec2(origin.x + visibleSize.width / 2,
// origin.y + visibleSize.height - 130));
// subtitle->setColor(Color3B::RED);
// // add the label as a child to this layer
// this->addChild(subtitle, 1);
// }
// add "HelloWorld" splash screen"
// auto sprite = Sprite::create("HelloWorld.png");
// if (sprite == nullptr)
// {
// problemLoading("'HelloWorld.png'");
// }
// else
// {
// // position the sprite on the center of the screen
// sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));//中間
//
// // add the sprite as a child to this layer
// this->addChild(sprite, 0);
// }
auto ui_interface = new MyUI;
if (ui_interface->init() == false) {
return false;
}
this->addChild(ui_interface, 2);
auto ui_game = new Table;
if (ui_game->init() == false) {
return false;
}
this->addChild(ui_game, 2);
return true;
}
void HelloWorld::menuCloseCallback(Ref* pSender)
{
//Close the cocos2d-x game scene and quit the application
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
/*To navigate back to native iOS screen(if present) without quitting the application ,do not use Director::getInstance()->end() and exit(0) as given above,instead trigger a custom event created in RootViewController.mm as below*/
//EventCustom customEndEvent("game_scene_close_event");
//_eventDispatcher->dispatchEvent(&customEndEvent);
}