【发布时间】:2014-09-20 21:53:31
【问题描述】:
我正在尝试在 cocos2d-x 中使用 CCTexture2D 创建一个矩形精灵。这是我的代码。
CCSprite *sprite = CCSprite::create();
GLubyte buffer[sizeof(GLubyte)*4];
buffer[0]=255;
buffer[sizeof(GLubyte)]=0;
buffer[sizeof(GLubyte)*2]=0;
buffer[sizeof(GLubyte)*3]=255;
CCTexture2D *texture = new CCTexture2D;
CCSize size = CCSize(100, 100);
texture->initWithData(buffer, kCCTexture2DPixelFormat_RGB5A1, 1, 1, size);
sprite->setTexture(texture);
sprite->setTextureRect(CCRectMake(0, 0, size.width, size.height));
this->addChild(sprite, 1);
问题是我没有得到矩形的预期颜色。使用上述缓冲区值,我得到蓝色。我不确定如何为 GLubyte 赋值(我也不知道 GLubyte 是如何工作的)。
提前致谢。
【问题讨论】: