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());

}





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

  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程小鱼酱

用心写好每一篇博客

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值