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
61
62
63
64
65
66
67
|
//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
;
//获取屏幕大小
auto
visibleSize = Director::getInstance()->getVisibleSize();
auto
size = Director::getInstance()->getWinSize();
//创建网格节点
auto
nodegrid = NodeGrid::create();
auto
sprite = Sprite::create(
"OnePiece_1.png"
);
sprite->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
nodegrid->addChild(sprite);
//这里注意是将精灵节点加到网格节点上
this
->addChild(nodegrid);
Director::getInstance()->setDepthTest(
false
);
//使用网格之前需要取消OpenGL的深度测试
// //翻页效果
// Director::getInstance()->setDepthTest(true); //开启深度检测
// auto pageturn = PageTurn3D::create(2, Size(20, 18));
// nodegrid->runAction(pageturn);
//
// //震动效果
// auto shaky = Shaky3D::create(6, Size(2, 1), 5, false);
// nodegrid->runAction(shaky);
//
// //翻转效果
// auto flipX = FlipX3D::create(2);
// auto reFlipX = flipX->reverse();
// auto delay = DelayTime::create(2); //延时2秒
// nodegrid->runAction(Sequence::create(flipX, delay, reFlipX, NULL));
//透镜效果
auto
lens = Lens3D::create(5, Size(32, 24), Vec2(size.width/2, size.height/2), 300);
//参数依次为:持续时间、网格大小、中心坐标、半径
nodegrid->runAction(lens);
// //液体效果
// auto liquid = Liquid::create(3, Size(16, 12), 4, 10); //参数依次为:持续时间、网格大小、波纹数、振幅
// nodegrid->runAction(liquid);
//
// //波纹效果
// auto ripple = Ripple3D::create(5, Size(20, 16), Vec2(size.width/2, size.height/2), 300, 6, 50);
// nodegrid->runAction(ripple);
//
// //波浪效果
// auto wave = Waves3D::create(5, Size(25, 20), 6, 30);
// nodegrid->runAction(wave);
return
true
;
}
|
备注:1、使用网格之前需要取消OpenGL的深度测试,深度其实就是该象素点在3d世界中距离摄象机的距离,深度缓存中存储着每个象素点(绘制在屏幕上的)的深度值,深度测试决定了是否绘制较远的象素点(或较近的象素点),通常选用较近的,而较远优先能实现透视的果;
2、32*24的网格看起来会觉得更舒服。