I have this cocos2dx (3.0 ~ 3.3) code (m_Texture and pixBuff are private members of HelloWorldScene) on Windows Phone 8:
In HelloWorldScene:init()
bool HelloWorldScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
srand(time(nullptr));
pixBuff = new int[100 * 100];
m_Texture = new Texture2D();
Size s;
s.width = 100;
s.height = 100;
m_Texture->initWithData(pixBuff, 100 * 100 * sizeof(int), Texture2D::PixelFormat::RGBA8888, s.width, s.height, s);
auto sprite = Sprite::createWithTexture(m_Texture);
sprite->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
this->addChild(sprite);
this->scheduleUpdate();
return true;
}
void HelloWorldScene::update(float delta)
{
for (int y = 0; y < 100; ++y) {
for (int x = 0; x < 100; ++x) {
pixBuff[y * 100 + x] = rand();
}
}
m_Texture->updateWithData(pixBuff, 0, 0, 100, 100);
}
HelloWorldScene::~HelloWorldScene() {
m_Texture->release();
delete[] pixBuff;
}
Everything go okay until I pressed “Windows” button to sent application to background and then pressed “Back” button to resume game, the texture goes black and stop the effect. How can I solve this problem?