Reputation:
I have 3 sets of sprite sheets for my first scene. I'm using XCode to develop for iOS using Cocos2D-X.
The first sprite sheet has an extension -sd, the second sprite sheet has -hd, and the third set has 3 sprite sheets (using Multipack in Texture Packer Pro) with the extension -ipadhd. I followed a tutorial and I found a method that goes like this
CCString* file = (Utils::getArtScaleFactor() > 1) ? CCString::create("randomFile-hd.plist") : CCString::create("randomFile-sd.plist");
//The Utils::getArtScaleFactor function
float Utils::getArtScaleFactor()
{
return artScaleFactor;
}
1- Is there a similar way to choose between 3 files instead of 2?
2- Is this the common method for choosing the appropriate file size-wise?
3- This question is somewhat off the topic I was discussing but I really need an answer to it too: I have an animation and its frames are split into 3 sprite sheets, how do I cache 3 .plist files? And if that's impossible, what are my options?
Hope I provided all the necessary information!
Regards
Upvotes: 1
Views: 385
Reputation: 1019
Sure, but that ternary operator should probably be switched out with another construct (like a switch) for clarity and flexibility.
For example:
// Always init your pointers.
CCString* file = NULL;
switch (Utils::getArtScaleFactor())
{
// Scale factor shouldn't ever be 0, but we should account for it
// so it doesn't get picked up by the default case.
case 0:
case 1:
file = CCString::create("randomFile-sd.plist");
break;
case 2:
file = CCString::create("randomFile-hd.plist");
break;
// Scale factors 3 and above get the largest resource.
default:
file = CCString::create("randomFile-super-hd.plist");
break;
}
Yes, this type of logic is on the wiki, except they use if-else for three resource sizes. I've seen it on the forums and tutorials, too.
According to this thread on the cocos2d-iphone forums, yes:
CCSprite can display CCSpriteFrames with different textures. So there’s no problem at all even to use animation that mixes frames from different textures (spritesheets) - Stepan Generalov
The implementations posted there are in obj-c but you can convert the cocos2d api calls to cpp easily.
Upvotes: 1