在cocos2d-xna中加入闪屏

用过ios中cocos2d的人都知道,我们在运行默认代码中,会看到一个闪屏+淡入的效果。而现在版本的cocos2d-xna是不带这个效果的,我觉得为了和绝大多数的wp7程序统一,还是应当加上闪屏的效果。

于是,我决定仿照ios版cocos2d来做一个cocos2d-xna的闪屏。

像是这样

OK,假定我们的闪屏场景叫做Splash,闪屏之后的菜单场景叫做MainMenuScene。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cocos2d;

namespace ChalkBall.Scene
{
    class SplashScene : CCScene
    {
        public override void onEnter()
        {
            base.onEnter();
            this.addChild(Splash.node());
        }
    }
    class Splash : CCLayer
    {
        CCDelayTime delayTime;
        public override bool init()
        {
            if (!base.init())
                return false;
            CCDirector.sharedDirector().deviceOrientation = ccDeviceOrientation.CCDeviceOrientationPortrait;
            CCSprite splash = CCSprite.spriteWithFile(@"images/Splash");
            splash.position = new CCPoint(240, 400);
            this.addChild(splash);
            delayTime = CCDelayTime.actionWithDuration(3);
            splash.runAction(delayTime);
            this.schedule(mackTranstion, 1);
            return true;
        }

        void mackTranstion(float dt)
        {
            if (delayTime.isDone())
            {
                MainMenuScene ms = new MainMenuScene();
                CCScene pScene = CCTransitionFade.transitionWithDuration(0.8f, ms);
                CCDirector.sharedDirector().replaceScene(pScene);
            }
        }

        public static new CCLayer node()
        {
            Splash layer = new Splash();
            if (layer.init())
            {
                return layer;
            }
            else
            {
                layer = null;
            }
            return layer;
        }
    }
}

需要解释的是delayTime = CCDelayTime.actionWithDuration(3);为闪屏停留的时间,CCTransitionFade为过渡时的特效,当然如果你不喜欢这个特效可以换成其他的。

这个闪屏的本质其实就是两个场景之间的切换,在闪屏场景中设定一个schedule,当时间到了之后进行切换。所以如果你想为场景间的切换增加特效,可以参考次方法,需要注意的是场景的实例化次数。

这样一个闪屏的效果就简单的完成了。

本文地址:http://www.cnblogs.com/jacklandrin/archive/2012/09/15/2687034.html

欢迎大家拍砖~

转载于:https://www.cnblogs.com/jacklandrin/archive/2012/09/15/jacklandrin.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值