Surz
Surz

Reputation: 1014

How to implement building a universal cococs2d application?

I am building an iphone application for iphone and ipad. I have texture packer .plists that contain my images. I have a normal version, an -hd version, an ipad version, and an ipadhd version.

For example, if I am currently building my menu, do I set all of them up by doing the following?

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"x_buttons.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"x_buttons-hd.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"s_buttons-ipad.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"s_buttons-ipadhd.plist"];

When I create a button, how does xcode 'know' which plist to use depending on the device? (iphone5, iphone4, retina, ipad etc etc)

Thank you for your help on making a universal application

Upvotes: 0

Views: 68

Answers (1)

Zhenghong Wang
Zhenghong Wang

Reputation: 2127

John

You only need to write [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"x_buttons.plist"];.

In AppDelegate.m's didFinishLaunchingWithOptions methond,
Change the following lines.

CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];  
[sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];    // Default on iPad RetinaDisplay is "-ipadhd"` 

This will help Xcode find your resource file by their suffix for iPad, iPad Retina, or iPhone Retina buildings.

Check this tutorial,
http://www.raywenderlich.com/32049/texture-packer-tutorial-how-to-create-and-optimize-sprite-sheets-in-cocos2d.

Upvotes: 2

Related Questions