cocos2d-x beta3 LayerColor не меняет цвет фона

не могу изменить цвет фона у меня есть этот простой класс:

вот файл с ++:

#include "HelloWorldScene.h"
USING_NS_CC;

HelloWorld::HelloWorld()
{
;
}
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();

// 'layer' is an autorelease object
auto layer = HelloWorld::create();

// add layer as a child to scene
scene->addChild(layer);

// return the scene
return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first

if ( !LayerColor::initWithColor(Color4B(20,0,0,255)) )
{
return false;
}
winSize = Director::getInstance()->getWinSize();
visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();

/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
//    you may modify it.

// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));

closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));

// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu, 1);

schedule( schedule_selector(HelloWorld::tick) );

return true;
}

void HelloWorld::onExit()
{
LayerColor::onExit();

}
void HelloWorld::onEnter()
{
LayerColor::onEnter();
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("interface/sprites.plist", "interface/sprites.png");
SpriteBatchNode* batch = SpriteBatchNode::create("interface/sprites.png");
this->addChild(batch,BATCH_Z);

auto listener = EventListenerTouchAllAtOnce::create();

listener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this);
listener->onTouchesMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this);
listener->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}void HelloWorld::onTouchesBegan(const std::vector<Touch*>& touches, Event  *event)
{
for( auto& touch : touches)
{}}

void HelloWorld::onTouchesMoved(const std::vector<Touch*>& touches, Event  *event)
{
for( auto& touch : touches)
{}
}

void HelloWorld::onTouchesEnded(const std::vector<Touch*>& touches, Event  *event)
{

for( auto& touch : touches)
{

startAnim = true;

};

}

void HelloWorld::tick(float dt)
{

if(startAnim)
{
}}void HelloWorld::draw()
{
LayerColor::draw();}HelloWorld::~HelloWorld()
{
// Removes Touch Event Listener
_eventDispatcher->removeEventListener(_touchListener);

}
void HelloWorld::menuCloseCallback(Object* pSender)
{
Director::getInstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}

и файл h:

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
class GameObj;
class ReelGameObj;

class HelloWorld : public cocos2d::LayerColor
{
public:

HelloWorld();
~HelloWorld();
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();

// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();

// a selector callback
void menuCloseCallback(Object* pSender);

// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);

void tick(float dt);
virtual void draw();
virtual void onEnter();
virtual void onExit();

void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event  *event);
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event  *event);
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event  *event);protected:
cocos2d::CustomCommand _customCommand;
void onDraw();
private:
cocos2d::EventListenerTouchOneByOne* _touchListener;
cocos2d::Size winSize;
cocos2d::Size visibleSize;
cocos2d::Point origin;

GameObj* pMainWindowObjCenter;
ReelGameObj* pReelGameObj;
bool startAnim;};

#endif // __HELLOWORLD_SCENE_H__

и ничего нет цвета на заднем плане, почему?
я работаю на Windows с VC 2012

1

Решение

Я думаю, что ваш цвет слишком темный. Попробуйте изменить значения на (255,25,255,255) и проверьте результат.

Я создал пример проекта (в бета-версии 2) и изменил только следующие строки:

.час:

class HelloWorld : public cocos2d::LayerColor

.каст:

if( !LayerColor::initWithColor(Color4B(255,255,255,255)) )

В результате получается белый фон.

3

Другие решения

Я очистил и обновил ваш код (я использую cocos2dx 2.2.1), и я мог бы изменить цвет слоя на красный.

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
class HelloWorld : public cocos2d::CCLayerColor
{
public:

HelloWorld();
~HelloWorld();
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::CCScene* createScene();

// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();

// a selector callback
void menuCloseCallback(CCObject* pSender);

// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);

virtual void onEnter();
void draw();
private:
cocos2d::CCSize winSize;
cocos2d::CCSize visibleSize;
cocos2d::CCPoint origin;

bool startAnim;
};

#endif // __HELLOWORLD_SCENE_H__

Файл cpp

#include "HelloWorldScene.h"
USING_NS_CC;

HelloWorld::HelloWorld()
{}

HelloWorld::~HelloWorld()
{}CCScene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = CCScene::create();

// 'layer' is an autorelease object
auto layer = HelloWorld::create();

// add layer as a child to scene
scene->addChild(layer);

// return the scene
return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first

ccColor4B c = ccc4(255,0,0,255);
if ( !CCLayerColor::initWithColor(c) )
{
return false;
}

return true;
}

void HelloWorld::onEnter()
{
CCLayerColor::onEnter();
}

void HelloWorld::draw()
{
CCLayerColor::draw();
}
0