I made two sets of spritesheets using TexturePacker
, one is called objects-0.plist
/objects0-png
and objects-0-ipad.plist
/objects-0-ipad.png
. Each of them has the following images in it:
// objects-0.plist / objects-0.png
object-0-0.png : 50x50 PNG file
object-0-1.png : 50x50 PNG file
object-0-2.png : 50x50 PNG file
// objects-0-ipad.plist / objects-0-ipad.png
object-0-0-ipad.png : 100x100 PNG file
object-0-1-ipad.png : 100x100 PNG file
object-0-2-ipad.png : 100x100 PNG file
I've loaded these up in the CCSpriteFrameCache
like so:
bool AnimTest::init( ) {
if ( !CCLayer::init( ) ) return false;
CCSpriteFrameCache::sharedSpriteFrameCache( ) -> addSpriteFrameWithFile( "objects-0.plist" );
}
Then, I tried making a CCSprite
object using one of the files in the .plist
file.
bool AnimTest::init( ) {
if ( !CCLayer::init( ) ) return false;
CCSpriteFrameCache::sharedSpriteFrameCache( ) -> addSpriteFrameWithFile( "objects-0.plist" );
CCSprite * testSprite = CCSprite::createWithSpriteFrameName( "object-0-0.png" );
this -> addChild( testSprite );
return true;
}
If I run this one from an iPod/iPhone, it works fine. However, if I run this from an iPad, CCSprite::createWithSpriteFrameName( )
throws an assert
saying the file name is invalid.
However, if I explicitly use the files with the -ipad
suffix, it works fine with no errors, which it should.
bool AnimTest::init( ) {
if ( !CCLayer::init( ) ) return false;
CCSpriteFrameCache::sharedSpriteFrameCache( ) -> addSpriteFrameWithFile( "objects-0-ipad.plist" );
CCSprite * testSprite = CCSprite::createWithSpriteFrameName( "object-0-0-ipad.png" );
this -> addChild( testSprite );
return true;
}
How can I fix this? Any help is appreciated.
Thought of an idea while writing the question which I only tested when it was sent and it worked.
The problem is that I'm retrieving the Sprite Frame directly from the file name. Meaning, I'm retrieving objects-0-0.png
and cocos2d-x
does not automatically use the suffixed version. So, knowing that, I re-made/re-wrote the .plist
file so that the two files (one with and one without suffix) have the same image file names, but are totally different images. The .plist
files and the .png
spritesheets are left with the suffixes.
Instead of:
// objects-0.plist / objects-0.png
object-0-0.png : 50x50 PNG file
object-0-1.png : 50x50 PNG file
object-0-2.png : 50x50 PNG file
// objects-0-ipad.plist / objects-0-ipad.png
object-0-0-ipad.png : 100x100 PNG file
object-0-1-ipad.png : 100x100 PNG file
object-0-2-ipad.png : 100x100 PNG file
Rename all the files inside the .plist
into those that don't use the suffix.
// objects-0.plist / objects-0.png
object-0-0.png : 50x50 PNG file
object-0-1.png : 50x50 PNG file
object-0-2.png : 50x50 PNG file
// objects-0-ipad.plist / objects-0-ipad.png
object-0-0.png : 100x100 PNG file
object-0-1.png : 100x100 PNG file
object-0-2.png : 100x100 PNG file