gpt4 book ai didi

c++ - cocos2d-x beta3 LayerColor 不改变背景色

转载 作者:可可西里 更新时间:2023-11-01 11:30:19 26 4
gpt4 key购买 nike

不能改变背景的颜色我有这个简单的类:

这是 C++ 文件:

#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__

背景中没有任何颜色,为什么?我正在使用 VC 2012 在 Windows 上工作

最佳答案

我觉得你的颜色太深了。尝试将值更改为 (255,25,255,255) 并检查结果。

我创建了一个示例项目(在 Beta 2 中),并且只更改了这些行:

.h:

class HelloWorld : public cocos2d::LayerColor

.cpp:

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

结果是白色背景。

关于c++ - cocos2d-x beta3 LayerColor 不改变背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21921078/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com