cocos-X加载场景,以及动作特效

前端之家收集整理的这篇文章主要介绍了cocos-X加载场景,以及动作特效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

新建一个类 newscene

class newscene : public cocos2d::Layer

{
public:
virtual bool init();
static cocos2d::Scene* createScene();
CREATE_FUNC(newscene);

};

实现函数

Scene * newscene::createScene(){
Scene*scene = Scene::create();
newscene *layer = newscene::create();
scene->addChild(layer);
return scene;
}
bool newscene::init(){
Size visiblesize = Director::getInstance()->getVisibleSize();
Sprite*s = Sprite::create("E:\\cocosproject\\dongtaijiazai\\proj.win32\\res\\222.jpg");
s->setPosition(visiblesize.width / 2,visiblesize.height / 2);
addChild(s);
return true;
}

上面是前戏,至于为什么就是因为要多一个场景来切换,所以有上面那么一出戏

接下来是重头戏

在HelloWorldScene.cpp中来敲下如下代码


// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visiblesize = Director::getInstance()->getVisibleSize();
Sprite*s = Sprite::create("E:\\cocosproject\\dongtaijiazai\\proj.win32\\res\\111.jpg");
s->setPosition(visiblesize.width / 2,visiblesize.height / 2);
addChild(s);

//这里我是让第一个图片,有一个旋转的特效,点题(标题
if (s){
s->runAction( cocos2d::RotateBy::create(1,360));
}

//事件侦听器
EventListenerTouchOneByOne*listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [s](Touch*t,Event*e){
if (s->getBoundingBox().containsPoint(s->convertToNodeSpace(t->getLocation())))
{
auto transitions = CCTransitionPageTurn::create(3,newscene::createScene(),1);
Director::getInstance()->replaceScene(transitions);
return true;
}
return true;
};

//好像用了闭包函数都有下面这一句,把事件侦听器链接起来
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraPHPriority(listener,s);
return true;
}


下面就是效果




原文链接:https://www.f2er.com/cocos2dx/344902.html

猜你在找的Cocos2d-x相关文章