* Please read the note in the next comment below*
I have a class derived from CCNode. The CCSprite object is NOT added to the CCNode as a child; instead the CCNode keeps a pointer to the CCSprite (you will see why in a minute). I subclass the draw() method and then draw my CCSprite at multiple locations on the screen. This works correctly for all circumstances except one.
If you press the power button (which minimizes the app and turns off the display), then restore the power and return to the app, I now have the background that was beneath my CCNode gone, and there is a “copy” of my sprite that was drawn multiple times left on the screen along with the new copies that are currently being drawn.
The code is like this:
m_pTexture = NULL;
m_pSprite = NULL;
MyNode::myInit( CCSprite *pSprite )
CCSize size = CCDirector::sharedDirector()->getWinSize();
m_pSprite = pSprite;
m_pSprite->setAnchorPoint( ccp( 0.5f, 0.5f ) );
m_pTexture = CCRenderTexture::create( (int)size.width, (int)size.height, kCCTexture2DPixelFormat_RGBA8888 );
setContentSize( CCSize( size.width, size.height ) );
m_pTexture->setPosition( ccp( ((int)size.width)>>1, ((int)size.height)>>1 ) );
addChild( m_pTexture );
if ( !m_pTexture )
// Begin the texture
m_pTexture->beginWithClear( 0, 0, 0, 0 );
m_pSprite->setVisible( true );
for( int i=0;i<5;i++ )
m_pSprite->setPosition( ccp( i*200 + 110, 384 ) );
// End the texture
m_pSprite->setVisible( false );
The code above works fine on Windows, iOS and Android for normal drawing. The only issue is when I minimize the app on Android and then restore, it doesn’t restore properly.
This seems to be some sort of OpenGL state issue, but I am not sure what it is. Does anyone have any ideas?