1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
//GameScene.h
#include "cocos2d.h"
class
GameScene :
public
cocos2d::Layer
{
public
:
static
cocos2d::Scene* createScene();
virtual
bool
init();
void
menuCallback(cocos2d::Ref* pSender);
CREATE_FUNC(GameScene);
};
|
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
|
//GameScene.cpp
//功能:瞬时动作的实现,精灵将在一瞬间完成指定动作
#include "GameScene.h"
USING_NS_CC;
cocos2d::Scene* GameScene::createScene()
{
auto
scene = Scene::create();
//创建一个场景
auto
layer = GameScene::create();
//创建一个图层
scene->addChild(layer);
return
scene;
}
//初始化当前的图层
bool
GameScene::init()
{
if
(!Layer::init())
//初始化父类
return
false
;
//获取屏幕大小
Size visibleSize = Director::getInstance()->getVisibleSize();
//auto size = Director::getInstance()->getWinSize();
//添加一个图片精灵
auto
sprite1 = Sprite::create(
"Flag_1.png"
);
sprite1->setPosition(Vec2(visibleSize.width/2, visibleSize.height*0.8));
this
->addChild(sprite1);
auto
sprite2 = Sprite::create(
"Flag_1.png"
);
sprite2->setPosition(Vec2(visibleSize.width/2, visibleSize.height*0.4));
this
->addChild(sprite2);
//沿X轴翻转
auto
flipX = FlipX::create(
true
);
sprite1->runAction(flipX);
//沿Y轴翻转
auto
flipY = FlipY::create(
true
);
sprite2->runAction(flipY);
//隐藏
auto
hide = Hide::create();
sprite2->runAction(hide);
//显示
auto
show = Show::create();
sprite2->runAction(show);
//放置
auto
place = Place::create(Vec2(visibleSize.width*0.8, visibleSize.height*0.8));
sprite1->runAction(place);
// //切换显示状态
// sprite1->runAction(ToggleVisibility::create());
return
true
;
}
|