转自 http://my.oschina.net/Jacedy/blog/301575?p=1
//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"
USING_NS_CC;
cocos2d::Scene*GameScene::createScene()
{
auto
scene=Scene::create();
//创建一个场景
layer=GameScene::create();
//创建一个图层
scene->addChild(layer);
return
scene;
}
//初始化当前的图层
GameScene::init()
{
if
(!Layer::init())
//初始化父类
return
false
;
//获取屏幕大小
visibleSize=Director::getInstance()->getVisibleSize();
size=Director::getInstance()->getWinSize();
//创建网格节点
nodegrid=NodeGrid::create();
sprite=Sprite::create(
"OnePiece_1.png"
);
sprite->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
nodegrid->addChild(sprite);
//这里注意是将精灵节点加到网格节点上
this
->addChild(nodegrid);
Director::getInstance()->setDepthTest(
);
//使用网格之前需要取消OpenGL的深度测试
//Director::getInstance()->setDepthTest(true);//开启深度检测
//autopageturn=PageTurn3D::create(2,Size(20,18));
//nodegrid->runAction(pageturn);
//
////震动效果
@H_404_222@//autoshaky=Shaky3D::create(6,Size(2,1),5,false);