Whenever I use
sprite = [CCSprite spriteWithFile:@"image.png"];
Cocos2d has always been intelligent enough to look for "image.png" on non retina devices and "image@2x.png" for retina devices.
But whenever I try to dynamically build out the sprite filename string i.e.
int random = arc4random() % 2;
switch (random) {
case 0:
color = @"blue";
break;
case 1:
color = @"green";
break;
default:
break;
}
filename = [[NSString alloc] initWithString:color];
filename = [filename stringByAppendingString:@"Square.png"];
// Sprite should now be either "greenSquare.png" or "blueSquare.png"
sprite = [CCSprite spriteWithFile:filename];
All of a sudden, my @2x files are being completely ignored - and cocos2d is only looking for files that are === "greenSquare.png" i.e. "greenSquare@2x.png" is never picked up, and if "greenSquare.png" doesn't exist (I was only testing with retina displays at the time) the entire app crashes.
Any idea why this is happening and what I can do to solve this?
(Ideally without having to manually check device retina status and then manually appending the @2x - since I know thats a possible solution it just doesn't seem like the right one).
Thanks!