1.导入readyTitle和guide的Sprite

2.设置点击监听事件

3.点击触发时从场景移除这2个元素

4.添加到GameScene里面


Guide.h

#pragma once

#include “cocos2d.h”

USING_NS_CC;

class Guide : public Layer

{

public:

Guide(void);

~Guide(void);

virtual bool init();

CREATE_FUNC(Guide);

void rmGuide();

private:

EventListenerTouchOneByOne * listener;

Sprite * title;

Sprite * guide;

};Guide.cpp

#include “Guide.h”

USING_NS_CC;

Guide::Guide(void)

{

}

Guide::~Guide(void)

{

}

bool Guide::init()

{

if (!Layer::init())

{

return false;

}

auto origin=Director::getInstance()->getVisibleOrigin();

auto visibleSize=Director::getInstance()->getVisibleSize();

//Ready标题

title = Sprite::createWithSpriteFrameName(“text_ready.png”);

title->setPosition(Point(origin.x+visibleSize.width*0.5,origin.y+visibleSize.height*0.8));

this->addChild(title);

//玩法提示

guide = Sprite::createWithSpriteFrameName(“tutorial.png”);

guide->setPosition(Point(origin.x+visibleSize.width*0.5,origin.y+visibleSize.height*0.4));

this->addChild(guide);

listener=EventListenerTouchOneByOne::create();

listener->onTouchBegan=[=](Touch * t,Event * e)

{

return true;

};

listener->onTouchEnded=[=](Touch *t,Event * e)

{

_eventDispatcher->removeEventListener(listener);

auto fade = FadeOut::create(0.5f);

auto fade_2 = FadeOut::create(0.5f);

//淡出之后,回调删除函数,从场景移除这2个对象

auto callback = CallFuncN::create(CC_CALLBACK_0(Guide::rmGuide,this));

auto sequence = Sequence::create(fade,callback,NULL);

guide->runAction(sequence);

title->runAction(fade_2);

};

_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,this);

return true;

}

//移除这2个元素

void Guide::rmGuide()

{

this->removeChild(title);

this->removeChild(guide);

}