cocos2dx3.2 实现splash屏幕简单实现

前端之家收集整理的这篇文章主要介绍了cocos2dx3.2 实现splash屏幕简单实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

首先将splash,像素480 * 800大图如下图:


切成四个小图(480 * 200)命名:SplashSlice_01.png,SplashSlice_02.png,SplashSlice_03.png,SplashSlice_04.png

然后再代码实现如下:

// SplashScene.cpp

// DontSaveMeGame

//

// Created by Mr Gan on 1/2/15.

//


#include"SplashScene.h"

#include "StartScene.h"

#include "../VisibleRect.h"


SplashScene::SplashScene()

{

}

SplashScene::~SplashScene()

{

_vcSprites.clear();


}


bool SplashScene::init()

{


if (!Scene::init())

{

return false;

}


for (int i = 0; i < 4; ++i)

{

auto fileName = String::createWithFormat("SplashSlice_0%d.png",i + 1);

auto sp = Sprite::create(fileName->getCString());

sp->setAnchorPoint(Vec2(0.5f,1.0f));

sp->setPosition(VisibleRect::top().x,VisibleRect::top().y - i * 200);

this->addChild(sp);

_vcSprites.pushBack(sp);


}

auto move1 = MoveBy::create(0.5,Vec2(0,-200));

auto move2 = MoveBy::create(0.5,200));


auto fun = cocos2d::CallFunc::create(CC_CALLBACK_0(SplashScene::afterFirst,this));

auto seq = Sequence::create(move1,fun, NULL);

_vcSprites.at(0)->runAction(seq);

_vcSprites.at(1)->runAction(move2);

return true;

}


void SplashScene::update(float dt)

{

auto scene = StartScene::create();

Director::getInstance()->replaceScene(scene);

}


void SplashScene::afterFirst()

{

auto move1 = MoveBy::create(0.5,200));

auto fun = cocos2d::CallFunc::create(CC_CALLBACK_0(SplashScene::afterSecond, NULL);

_vcSprites.at(0)->runAction(seq);

_vcSprites.at(2)->runAction(move2);



}


void SplashScene::afterSecond()

{

auto move1 = MoveBy::create(0.5,200));

auto delay = DelayTime::create(0);


auto fun = cocos2d::CallFunc::create(CC_CALLBACK_0(SplashScene::beginGame,this));

auto seq = Sequence::create(move1,delay,NULL);

_vcSprites.at(0)->runAction(seq);

_vcSprites.at(3)->runAction(move2);


}



void SplashScene::beginGame()

{

auto scene = StartScene::create();

auto tranScene = TransitionZoomFlipX::create(2.0f,scene,TransitionScene::Orientation::LEFT_OVER);

@H_504_404@ Director::getInstance()->replaceScene(tranScene);


}

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

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