iOS Universal Application 支持IPHONE和IPAD的应用设置

//实现  320*180  640*960 768*1024 1536*2048 四种分辨率的图片加载

//在AppDelegate中把起用高清的代码注释去掉

//if( ! [director enableRetinaDisplay:YES] )

//CCLOG(@"Retina Display Not supported");

//在ccConfig 中把-hd去掉,这是cocos2d默认起用高清的文件,和我当时定义的不符,我就去掉了

//#define CC_RETINA_DISPLAY_FILENAME_SUFFIX @"-hd"  改成  #define CC_RETINA_DISPLAY_FILENAME_SUFFIX @""  

#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

//验证是否是视网模屏

#define isIphoneRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)]?CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

#define isIpadRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)]?CGSizeEqualToSize(CGSizeMake(2048, 1536), [[UIScreen mainScreen] currentMode].size) : NO)

#define I_PNG           @".png"

#define SD_PNG         @"-iphone-sd.png"

#define SD_IPHONE_PNG  @"-iphone-hd.png"

#define HD_PNG         @"-ipad-sd.png"

#define HD_IPAD_PNG    @"-ipad-hd.png"

//取图片

#define IMG_GET(__filename__)  (isPad == YES ?             \

((isIpadRetina==YES)?[__filename__ stringByReplacingOccurrencesOfString:I_PNG withString:HD_IPAD_PNG]: \

[__filename__ stringByReplacingOccurrencesOfString:I_PNG withString:HD_PNG]) :  \

((isIphoneRetina==YES)?[__filename__ stringByReplacingOccurrencesOfString:I_PNG withString:SD_IPHONE_PNG]: \

[__filename__ stringByReplacingOccurrencesOfString:I_PNG withString:SD_PNG]))

//同步iphone和ipad的坐标

#define TO_X(__x__) (isPad == YES ? ( __x__ * 2.133333 ) : ( __x__ ) )

#define TO_Y(__y__) (isPad == YES ? ( __y__ * 2.133333 ) : ( __y__ ) )

#define TO_XY(__x__, __y__)     \

(isPad == YES ?                     \

ccp( ( __x__ * 2.133333 ), ( __y__ * 2.133333 )) : \

ccp(__x__, (__y__)))

//使用演示====================================

 CCSprite *goodGuy = [CCSprite spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:IMG_GET("default.png")]];

 [self addChild:goodGuy];

//上述代码参考了以下网址

//=============================================================

http://jonathanhui.com/ios-universal-application

http://www.slideshare.net/cliffmcc/creating-a-universal-ios-application

http://stackoverflow.com/questions/3320355/how-should-i-approach-building-a-universal-ios-app-that-will-include-ios-4-featu

https://github.com/kstenerud/iOS-Universal-Framework

Universal cocos2d game to support iPad3

http://stackoverflow.com/questions/9623720/universal-cocos2d-game-to-support-ipad3 

http://michaelgilkes.info/cocos2d-using-hd-images-for-ipad-in-a-universal-app/

http://stackoverflow.com/questions/3320355/how-should-i-approach-building-a-universal-ios-app-that-will-include-ios-4-featu

cocos2d 官方高清图解决方案

http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:how_to_develop_retinadisplay_games_in_cocos2d

http://michaelgilkes.info/cocos2d-using-hd-images-for-ipad-in-a-universal-app/

http://stackoverflow.com/questions/9623720/universal-cocos2d-game-to-support-ipad3

转载于:https://my.oschina.net/ahuaahua/blog/50320

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值