https://img-blog.csdnimg.cn/32db9ce43ef64316a2e37a31f4cee033.gif
编程小鱼酱yu612.com,点击前往

Cocos2d-3.x 开机logo动画实例

1.淡入淡出动画

     最近在做一个项目,分享给大家一个不错的例子,我们可以用这个模板去设计我们的游戏开机动画哦。

2.效果如下



3.例子如下



AppDelegate加入如下代码,记住导入LogoScene的头文件

    // create a scene. it's an autorelease object
    auto scene = LogoScene::createScene();

    // run
    director->runWithScene(scene);
    return true;



  

//LogoScene类

#include "LogoScene.h"
#include "AppDelegate.h"



USING_NS_CC;

Scene* LogoScene::createScene()
{
    auto scene = Scene::create();	
    auto layer = LogoScene::create();
	auto s = Director::getInstance()->getVisibleSize();
	//开机第一张图片,选择自己喜欢的图片哦
	Sprite* pSprite = Sprite::create("logo_telecom.png");

	if (pSprite)
	{
		//屏幕的位置
		pSprite->setPosition(s.width/2,s.height/2);
		//99号节点
		layer->addChild(pSprite, 0, 99);
	}

	scene->addChild(layer);
    return scene;
}

// on "init" you need to initialize your instance
bool LogoScene::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
	auto pCCLayerColor = LayerColor::create(Color4B(255, 255, 255, 255));
	addChild(pCCLayerColor);
	scheduleOnce(schedule_selector(LogoScene::logoshowCallback), 1.0f);
    return true;
}


void LogoScene::logoshowCallback(float temp)
{
	{
		//背景图淡入消去
		Sprite* pSprite = (Sprite*)(getChildByTag(99));
		FadeOut* pAction = FadeOut::create(0.625f);
		pSprite->runAction(pAction);
	}

	auto pCCLayerColor = LayerColor::create(Color4B(255, 255, 255, 255));
	{	
		//延迟纯白色背景加载0.625秒动作
		addChild(pCCLayerColor);
		pCCLayerColor->setOpacity(0);
		DelayTime* pAction1 = DelayTime::create(0.625f);
		FadeIn* pAction2 = FadeIn::create(0.625f);
		//DelayTime* pAction3 = DelayTime::create(1.0f);
		pCCLayerColor->runAction(Sequence::create(pAction1, pAction2, NULL));
	}

	auto s = Director::getInstance()->getVisibleSize();
	//logo的图片
	Sprite* pSprite = Sprite::create("gamedo.png");
	{
		pSprite->setPosition(s.width / 2, s.height / 2);
		pCCLayerColor->addChild(pSprite);
		pSprite->setOpacity(0);
		DelayTime* pAction1 = DelayTime::create(0.625f);
		FadeIn* pAction2 = CCFadeIn::create(0.625f);
		//DelayTime* pAction3 = DelayTime::create(1.0f);
		pSprite->runAction(Sequence::create(pAction1, pAction2, NULL));
	}

	scheduleOnce(schedule_selector(LogoScene::logoshowOver), 2.00f);
}

void LogoScene::logoshowOver(float temp)
{
	//场景迁移 ,这里我们以后可以单独做一个 控制场景迁移的类
	//CCDirector::sharedDirector()->replaceScene(MainScene::Create());

}





   不懂的大家可以在下面留言哦~

  
posted @ 2016-05-26 23:35  鱼酱  阅读(199)  评论(0编辑  收藏  举报

https://img-blog.csdnimg.cn/32db9ce43ef64316a2e37a31f4cee033.gif
编程小鱼酱yu612.com,点击前往