cocos2dx一个场景增添多个层
给一个场景添加两个层吧。 首先创建两个layer,以下是头文件
#pragma once #include "cocos2d.h" USING_NS_CC; class BackgroundLayer : public cocos2d::CCLayer { public: virtual bool init(); CREATE_FUNC(BackgroundLayer); }; #pragma once #include "cocos2d.h" USING_NS_CC; class FishLayer : public cocos2d::CCLayer { public: virtual bool init(); CREATE_FUNC(FishLayer); }; 现在去源文件实现一下:
#include "BackgroundLayer.h"
bool BackgroundLayer::init()
{
CCSprite* bg = CCSprite::create("bg.png");
bg->setPosition(ccp(visiblesize.width/2,visiblesize.height/2));
addChild(bg);
return true;
}
#include "FishLayer.h"
bool FishLayer::init()
{
CCSprite* bg = CCSprite::create("bgfish.png");
bg->setPosition(ccp(visiblesize.width/2,204)"> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |