1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//GameScene.h
#include"cocos2d.h"
class
GameScene:
public
cocos2d::Layer
{
:
static
cocos2d::Scene*createScene();
virtual
bool
init();
void
menuCallback(cocos2d::Ref*pSender);
CREATE_FUNC(GameScene);
};
|
//GameScene.cpp
#include"GameScene.h"
#include"HelloWorldScene.h"
USING_NS_CC;
cocos2d::Scene*GameScene::createScene()
{
auto
scene=Scene::create();
//创建一个场景
layer=GameScene::create();
//创建一个图层
scene->addChild(layer);
return
scene;
}
//初始化当前的图层
GameScene::init()
{
return
false
;
SizevisibleSize=Director::getInstance()->getVisibleSize();
//获取屏幕大小
sprite1=Sprite::create(
"game.png"
);
sprite1->setAnchorPoint(Point::ZERO);
//设置锚点在左下角,原锚点位置在中心
sprite1->setPosition(Point(0,0));
//sprite1->setPosition(Point(visibleSize.width/2,visibleSize.height/2));
this
->addChild(sprite1);
backItem=MenuItemImage::create(
"CloseNormal.png"
,
"CloseSelected.png"
backItem->setPosition(Point(visibleSize.width-50,50));
menu=Menu::create(backItem,NULL);
menu->setPosition(Point::ZERO);
->addChild(menu,1);
true
;
}
//从游戏场景跳转到Hello场景
GameScene::menuCallback(cocos2d::Ref*pSender)
{
//方法一
//autoscene=HelloWorld::createScene();//创建一个新场景,因为原场景已删除
//Director::getInstance()->replaceScene(scene);
//方法二
Director::getInstance()->popScene();
//原场景依然存在,直接出栈
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//GameScene.h
#include"cocos2d.h"
class
GameScene:
public
cocos2d::Layer
{
:
static
cocos2d::Scene*createScene();
virtual
bool
init();
void
menuCallback(cocos2d::Ref*pSender);
CREATE_FUNC(GameScene);
};
|
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
#include"GameScene.h"
#include"HelloWorldScene.h"
USING_NS_CC;
cocos2d::Scene*GameScene::createScene()
{
auto
scene=Scene::create();
//创建一个场景
layer=GameScene::create();
//创建一个图层
scene->addChild(layer);
return
scene;
}
//初始化当前的图层
GameScene::init()
{
return
false
;
SizevisibleSize=Director::getInstance()->getVisibleSize();
//获取屏幕大小
sprite1=Sprite::create(
"game.png"
);
sprite1->setAnchorPoint(Point::ZERO);
//设置锚点在左下角,原锚点位置在中心
this
->addChild(sprite1);
调用menuCallback方法
backItem=MenuItemImage::create(
"CloseNormal.png"
"CloseSelected.png"
));
menu->setPosition(Point::ZERO);
true
;
}
//从游戏场景跳转到Hello场景
GameScene::menuCallback(cocos2d::Ref*pSender)
{
//方法一
//autoscene=HelloWorld::createScene();//创建一个新场景,因为原场景已删除
//Director::getInstance()->replaceScene(scene);
//方法二
Director::getInstance()->popScene();
//原场景依然存在,直接出栈
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//GameScene.h
#include"cocos2d.h"
class
GameScene:
public
cocos2d::Layer
{
:
static
cocos2d::Scene*createScene();
virtual
bool
init();
void
menuCallback(cocos2d::Ref*pSender);
CREATE_FUNC(GameScene);
};
|
//GameScene.cpp
#include"GameScene.h"
#include"HelloWorldScene.h"
USING_NS_CC;
cocos2d::Scene*GameScene::createScene()
{
auto
scene=Scene::create();
//创建一个场景
layer=GameScene::create();
//创建一个图层
scene->addChild(layer);
return
scene;
}
//初始化当前的图层
GameScene::init()
{
return
false
;
SizevisibleSize=Director::getInstance()->getVisibleSize();
//获取屏幕大小
sprite1=Sprite::create(
"game.png"
);
sprite1->setAnchorPoint(Point::ZERO);
//设置锚点在左下角,原锚点位置在中心
调用menuCallback方法
backItem=MenuItemImage::create(
"CloseNormal.png"
true
;
}
//从游戏场景跳转到Hello场景
GameScene::menuCallback(cocos2d::Ref*pSender)
{
//方法一
//autoscene=HelloWorld::createScene();//创建一个新场景,因为原场景已删除
//Director::getInstance()->replaceScene(scene);
//方法二
Director::getInstance()->popScene();
//原场景依然存在,直接出栈
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//GameScene.h
#include"cocos2d.h"
class
GameScene:
public
cocos2d::Layer
{
:
static
cocos2d::Scene*createScene();
virtual
bool
init();
void
menuCallback(cocos2d::Ref*pSender);
CREATE_FUNC(GameScene);
};
|
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
#include"GameScene.h"
#include"HelloWorldScene.h"
USING_NS_CC;
cocos2d::Scene*GameScene::createScene()
{
auto
scene=Scene::create();
//创建一个场景
layer=GameScene::create();
//创建一个图层
scene->addChild(layer);
return
scene;
}
//初始化当前的图层
GameScene::init()
{
return
false
;
SizevisibleSize=Director::getInstance()->getVisibleSize();
//获取屏幕大小
sprite1=Sprite::create(
"game.png"
);
sprite1->setAnchorPoint(Point::ZERO);
//设置锚点在左下角,原锚点位置在中心
this
->addChild(sprite1);
调用menuCallback方法
backItem=MenuItemImage::create(
"CloseNormal.png"
"CloseSelected.png"
));
menu->setPosition(Point::ZERO);
true
;
}
//从游戏场景跳转到Hello场景
GameScene::menuCallback(cocos2d::Ref*pSender)
{
//方法一
//autoscene=HelloWorld::createScene();//创建一个新场景,因为原场景已删除
//Director::getInstance()->replaceScene(scene);
//方法二
Director::getInstance()->popScene();
//原场景依然存在,直接出栈
}