返回场景和音乐

  1. 播放背景音乐,实时音乐

    1. #include “SimpleAudioEngine.h”
    2. CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(“pew-pew-lei.wav”); // 实时音乐
    3. CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(“background-music-aac.wav”, true);// 循环播放背景音
  2. 创建一个自己的场景
    可以实现场景之间的切换,可以实现延时动作。
    // GameOverLayer.h

include “cocos2d.h”

class GameOverLayer :public cocos2d::CCLayerColor
{
public:
cocos2d::CCLabelTTF * _label;
bool init ();
~ GameOverLayer();

             static cocos2d ::CCScene* scene();
             CREATE_FUNC(GameOverLayer );
             void returnToGame (cocos2d:: CCNode*);
             // CCLabelTTF::create()  HelloWorld::create()

};

// GameOverLayer.cpp

include “GameOverLayer.h” ;

include “HelloWorldScene.h” ;

USING_NS_CC;

bool GameOverLayer ::init()
{
if (CCLayerColor ::initWithColor( ccc4(0, 255, 0, 255)) != NULL )
{
_label = CCLabelTTF ::create( “word”, “Artial” , 40);
CCSize size = CCDirector:: sharedDirector()->getVisibleSize ();

                             _label->setPosition (ccp(size.width / 2, size.height / 2));

                             this->addChild (_label);;

                             _label->retain (); //保证_label 跟类对象有同样的生命周期

                             CCDelayTime* delay = CCDelayTime:: create(5);//延迟5秒 // 执行一个延时动作

                             CCCallFuncN* returnToGame = CCCallFuncN:: create(this , callfuncN_selector(GameOverLayer ::returnToGame));
                             this->runAction (CCSequence:: create(delay , returnToGame, NULL));
                             return true ;

            }
             return false ;

}
void GameOverLayer ::returnToGame( CCNode* )
{
CCDirector::sharedDirector ()->replaceScene( HelloWorld::scene ()); // 场景之间切换
}

GameOverLayer::~GameOverLayer ()
{
if (_label )
{
_label->release ();
}
}

cocos2d::CCScene * GameOverLayer:: scene()
{
CCScene* scene = CCScene:: create();
GameOverLayer* layer = GameOverLayer:: create();
layer->setTag (100);
scene->addChild (layer);

             return scene ; 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值