I am making a game using playing card images. In my setup phase where i draw the initial state, everything is fine. As the game progresses, sometimes CCSprites do not render at all at the target location. It happens on iOS and Android, both on device and simulator, so i’m pretty sure the issue is in my code.
Platforms: iOS and Android. Happens on physical devices and mobile, different resolutions, etc.
Cocos2dx version: 2.1.1 beta 3
I can confirm the filename, target position, etc. are correct for the CCSprite. So my guess is that I am rendering at the wrong time or something.
I attached a screenshot of what happens: Notice how the top row of cards has some gaps. These are examples of the failures. It is simply a loop that renders cards as follows:
for (int i = 51; i >=0; i--){
CCSize winSize = getWinSize();
CCSprite *card = CCSprite::create("ab1fv.png");
card->setScale(CC_CONTENT_SCALE_FACTOR());
card->setPosition(ccp(winSize.width / 2 - card->boundingBox().size.width/2 + 10 + (i * 2),
winSize.height - card->boundingBox().size.height/3*2) );
addChild(card);
remainingCardSprites.push(card);
}
I run this code once at the beginning of each game. The first game is always fine, the errors happen more and more as the game goes on.
I think it’s strange that it works most of the time but randomly seems to fail. If you look at the 2nd pile of cards, there’s also a missing ace in between the 2 and the 10 (adding up to 18 total). Sometimes when i restart the game the background does not render and is all black. So it seems to happen to all my CCSprites. They all use similar code to what I posted.
The CCSprite object seems to be incorrectly created, since the application crashes when i try to get the bounding box of the referenced sprite.
Let me know if you need any more source!
IMG_0018.PNG (211.4 KB)