2010-07-20 20 views
43

के बीच अंतर कैसे करें मैं cocos2d इंजन का उपयोग कर आईफोन के लिए एक गेम बनाने की कोशिश कर रहा हूं। मैं जानना चाहता था कि मैं एक अंतर कैसे बता सकता हूं कि उपयोगकर्ता आईफोन 4 या आईफोन 3 का उपयोग कर रहा है क्योंकि मैं iphone4 के लिए हाय-रेज़ोल्यूशन ग्राफिक्स लोड करना चाहता था और आईफोन 3 के लिए कम-रिज़ॉल्यूशन लोड करना चाहता था। मुझे पता है कि मैं @ 2x.png का उपयोग करता हूं छवि फ़ाइल नाम का अंत UIImage उच्च-रिज़ॉल्यूशन छवि को स्वयं लोड करता है अगर मैं एक आईफोन 4 का उपयोग कर रहा हूं लेकिन गेम के लिए मैं ग्राफिक्स लोड करने के लिए cocos2d इंजन की CCSprite क्लास का उपयोग कर रहा हूं।iphone4 और iphone 3

मैं वास्तव में उत्तर की सराहना करता हूं।

सादर, अंकुर

उत्तर

123

आप स्क्रीन के पैमाने की जांच कर सकता।

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){ 
    //iPhone 4 
} 
+2

बस ध्यान रखें कि पैमाने आईपैड पर भी उपलब्ध है हो ओएस 3.2 में, सिर्फ आईओएस पर नहीं। –

+0

दाएं, लेकिन आईपैड का स्तर 2. –

+3

असल में, आईपैड का स्तर 2x ज़ूम मोड में 2 है। –

3

एप्पल डॉक्स क्या कहते हैं के बावजूद, UIScreen के पैमाने संपत्ति, iOS4 में बस उपलब्ध नहीं है यह आईपैड पर 3.2 में भी उपलब्ध है। इसका मतलब है कि यह जांचने का एक अविश्वसनीय तरीका है कि आप किस डिवाइस पर हैं।

इसके बजाय, आप अगर contentScaleFactor अपने मुख्य विंडो (या किसी भी UIView) पर उपलब्ध है की जाँच करनी चाहिए, और फिर पैमाने मूल्य की जाँच करें।

+1

दुर्भाग्य से, ContentScaleFactor आईओएस 4 में भी नया है, इसलिए यह स्केल प्रॉपर्टी के मुकाबले पीछे की संगतता के साथ मदद नहीं करता है। मुझे आश्चर्य है कि अगर उपयोगकर्ता आईपैड पर "2x" बटन पर क्लिक करता है तो यह 1 से 2 उड़ान भरता है? –

+1

यह 3.2 में है, इसलिए मुझे लगता है कि यह 4.2 में भी होगा, मैंने हालांकि जांच नहीं की है। –

3

scale संपत्ति की जांच करना पर्याप्त नहीं है, क्योंकि 2x मोड में आईपैड 3.2 पर, scale संपत्ति मौजूद है और 2.0 लौटाएगी, लेकिन हम जानते हैं कि डिवाइस में रेटिना डिस्प्ले नहीं है।

मैंने ऐसा करने के लिए UIScreen पर श्रेणी में बनाया है। अधिक विस्तृत स्पष्टीकरण के लिए, मेरा उत्तर Detect Retina Display पर देखें। कोड यह रहा:

@interface UIScreen(ZBScreenRetinaAdditions) 

// Returns YES if this is a Retina display. 
- (BOOL)zb_isRetina; 

@end 

@implementation UIScreen(ZBScreenRetinaAdditions) 

- (BOOL)zb_isRetina { 
    return [self respondsToSelector:@selector(displayLinkWithTarget:selector:)] && (self.scale == 2.0); 
} 

@end 

प्रयोग उदाहरण:

if ([UIScreen mainScreen] zb_isRetina) { 
    // Retina display 
} 
+1

बस उत्सुक ... आपके पास क्यों है? हां: अंत में नहीं? आपके कोड में जरूरी नहीं है, है ना? – donkim

+0

आप सही हैं, यह अनावश्यक है। यह शैली एक बुरी आदत है जिसे मैंने कुछ उदाहरणों से उठाया जब मैं पहली बार उद्देश्य-सी सीख रहा था। फिक्स्ड। – sickp

2

सिर्फ मेरी 2 सेंट जोड़ने:

मैं देख रहा हूँ कि तुम क्या यहाँ एक विशिष्ट मूल्य के कर रहे हैं, लेकिन बाध्यकारी इस 2.0 की तरह अच्छा है इस पल के लिए, लेकिन क्या होगा अगर उदाहरण के लिए अगले आईपैड को x1.5 की तरह रिज़ॉल्यूशन टक्कर मिल गई? मेरे लिए 1.0 से ऊपर जो भी कुछ भी सामान्य डिस्प्ले से अधिक है, इसलिए मैं हाय-रेज ग्राफिक्स लोड करूंगा। ज्यादा तो कोई प्रभाव नहीं पड़ेगा कि अगर iPad, iPhone है ....

5
- (NSString *) platform 
{ 
    size_t size; 
    sysctlbyname("hw.machine", NULL, &size, NULL, 0); 
    char *machine = malloc(size); 
    sysctlbyname("hw.machine", machine, &size, NULL, 0); 
    NSString *platform = [NSString stringWithCString:machine]; 
    free(machine); 
    return platform; 
} 

- (NSString *) platformString 
{ 
    NSString *platform = [self platform]; 
    if ([platform isEqualToString:@"iPhone1,1"]) return @"Original iPhone"; 
    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G"; 
    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3G[S]"; 
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4"; 
    return @"Unknown"; 
} 
2

मुझे पता है कि विषय अब थोड़ा पुराना है, लेकिन यह कुछ लोगों को मदद कर सकता है। Cocos2d पर आप iphone4 के लिए उच्च-रिज़ॉल्यूशन ग्राफिक्स लोड कर सकते हैं और आईफोन 3 के लिए कम-रिज़ॉल्यूशन को अपनी फ़ाइलों पर -hd प्रत्यय का उपयोग कर लोड कर सकते हैं। यहाँ दस्तावेज़ पढ़ें

// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices 
if(! [director enableRetinaDisplay:YES]) 
    CCLOG(@"Retina Display Not supported"); 

अधिक जानकारी के लिए:

तुम बस इस से पहले की तरह रेटिना प्रदर्शन सक्षम करने के लिए RetinaDisplay in cocos2d

0

पैमाने आईपैड के लिए उपलब्ध है, फिर भी तुम हमेशा अगर (UI_USER_INTERFACE_IDIOM उपयोग कर सकते हैं() == UIUserInterfaceIdiomPad) क्या यह iPad या iPhone/iTouch

2

आयात "UIScreen + रेटिना है की जाँच करने के।ज "

if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){ 
    //IPAD   
    if ([[UIScreen mainScreen] isRetina]) { 
     // IPAD 3 - Retina display 
     bannersGetPromoServerRequest.size = kXML_API_IMAGESIZE_IPAD_HIGHRES;    
    }else{ 
     //iPAD 1/2 
     bannersGetPromoServerRequest.size = kXML_API_IMAGESIZE_IPAD_LOWRES;  } 
}else{ 
    //IPHONE 
    if ([[UIScreen mainScreen] isRetina]) { 
     // IPHONE 4/4s/5 - Retina display 
     bannersGetPromoServerRequest.size = kXML_API_IMAGESIZE_IPHONE_HIGHRES; 

    }else{ 
     //IPHONE (3.x) 
     bannersGetPromoServerRequest.size = kXML_API_IMAGESIZE_IPHONE_LOWRES; 

    } 
} 
12

सहित सभी उपकरणों पर रेटिना प्रदर्शन का पता लगाने के नए iPad के लिए

+(BOOL)isRetinaDisplay { 
    // since we call this alot, cache it 
    static CGFloat scale = 0.0; 
    if (scale == 0.0) { 
     // NOTE: In order to detect the Retina display reliably on all iOS devices, 
     // you need to check if the device is running iOS4+ and if the 
     // [UIScreen mainScreen].scale property is equal to 2.0. 
     // You CANNOT assume a device is running iOS4+ if the scale property exists, 
     // as the iPad 3.2 also contains this property. 
     // On an iPad running iOS3.2, scale will return 1.0 in 1x mode, and 2.0 
     // in 2x mode -- even though we know that device does not contain a Retina display. 
     // Apple changed this behavior in iOS4.2 for the iPad: it returns 1.0 in both 
     // 1x and 2x modes. You can test this yourself in the simulator. 
     // I test for the -displayLinkWithTarget:selector: method on the main screen 
     // which exists in iOS4.x but not iOS3.2, and then check the screen's scale: 

     if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && 
      ([UIScreen mainScreen].scale == 2.0)) { 
      scale = 2.0; 
      return YES; 
     } else { 
      scale = 1.0; 
      return NO; 
     } 

    } 
    return scale > 1.0; 
} 

क्रेडिट करने के लिए: एड्रियानो Paladini http://developer.appcelerator.com/question/133826/detecting-new-ipad-3-dpi-and-retina