
cocos2d-iphone v2.1-beta2 is available for download:
Although it is a tiny release, it includes important changes. Highlights:
- Updated templates: Compatible with iPhone 5 Retina Display, and fixes in Mac templates
- LabelTTF works on Mac Retina Display
Full Changelog: CHANGELOG
API Reference: v2.1 API Ref
I would appreciate if you could test it and report any possible bug that you might find. Thanks.






Is there a 1.1-beta3 coming soon?
@kokernutz:
Yes. For further info, please read this thread: http://www.cocos2d-iphone.org/forum/topic/38990
I just installed beta2 and after creating a new project (with Chipmunk included) and following http://www.learn-cocos2d.com/2012/04/enable-arc-cocos2d-project-video-tutorial/ to make my code use ARC I get compile errors when I try to refactor the code to Objective-C ARC.
The error i get is in ccTypes.h “Semantic Issue – Type ‘float’ cannot be narrowed to ‘GLubye’ (aka ‘unsigned char’) in initializer list”.
Error is related to the ccc4BFromccc4F method (line 144).
Funny thing is that I have done this many times before with version 2.0 with success and have never had any issues.
When I compile without trying to make it running ARC it works perfectly fine. But adding the Lib folder to the static library seems to make the error happen.
On Mountain Lion 10.8.1 with Xcode 4.4.1
I see the only one template ‘Cocos2D iOS’ :-/
http://dl.dropbox.com/u/8247035/Misc/Cocos2D/1.png
http://dl.dropbox.com/u/8247035/Misc/Cocos2D/2.png
http://dl.dropbox.com/u/8247035/Misc/Cocos2D/3.png
…And after creation of test project some files on Resources folder are Zero bytes:
http://dl.dropbox.com/u/8247035/Misc/Cocos2D/x2-2.png
http://dl.dropbox.com/u/8247035/Misc/Cocos2D/x2-1.png
@Kovaloid:
How did you uncompress the tar.gz file ?
Did you use “The Unarchiver” ? Apparently there is has a bug with tar.gz files. Try to disable it for “tar.gz” files, or uncompress them manually. eg:
$ tar xzvf cocoso2d-iphone-2.1-beta2.tar.gz
@riq
Many thanks!
You’re right I’ve used “The Unarchiver” app. Native “Archive Utility” works fine. Now I see four templates for iOS and four for Mac in Xcode. Thanks again =)
I’ve noticed a couple of problems with box2d:
1. 14 warnings about unused variables in box2d files
2. textures are two times smaller than they should be when run on 3.5 retina device and two times bigger when run on 3.5 and 4 retinas.
I mean the default textures from project template
works fine, I just added suffix support for Iphone 5 for it by myself.
here’s the code, (just add an entry in the app delegate ([sharedFileUtils setiPhone5RetinaDisplaySuffix:@"-568h"];) and the ccTypes (kCCResolutioniPhone5RetinaDisplay)
.h
/*
* cocos2d for iPhone: http://www.cocos2d-iphone.org
*
* Copyright (c) 2008-2010 Ricardo Quesada
* Copyright (c) 2011 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#import
#import “../ccTypes.h”
/** Helper class to handle file operations */
@interface CCFileUtils : NSObject
{
NSFileManager *fileManager_;
NSBundle *bundle_;
NSMutableDictionary *fullPathCache_;
NSMutableDictionary *removeSuffixCache_;
BOOL enableFallbackSuffixes_;
#ifdef __CC_PLATFORM_IOS
NSString *iPhoneRetinaDisplaySuffix_;
NSString *iPhoneRetina5DisplaySuffix_;
NSString *iPadSuffix_;
NSString *iPadRetinaDisplaySuffix_;
#elif defined(__CC_PLATFORM_MAC)
NSString *macSuffix_;
NSString *macRetinaDisplaySuffix_;
#endif // __CC_PLATFORM_MAC
}
/** NSBundle used by CCFileUtils. By default it uses [NSBundle mainBundle].
@since v2.0
*/
@property (nonatomic, readwrite, retain) NSBundle *bundle;
/** NSFileManager used by CCFileUtils. By default it uses its own instance.
@since v2.0
*/
@property (nonatomic, readwrite, retain) NSFileManager *fileManager;
/** Whether of not the fallback suffixes is enabled.
When enabled it will try to search for the following suffixes in the following order until one is found:
* On iPad HD : iPad HD suffix, iPad suffix, iPhone HD suffix, Without suffix
* On iPad : iPad suffix, iPhone HD suffix, Without suffix
* On iPhone HD: iPhone HD suffix, Without suffix
* On Mac HD : Mac HD suffix, Mac suffix, Without suffix
* On Mac : Mac suffix, Without suffix
By default this functionality is off;
*/
@property (nonatomic, readwrite) BOOL enableFallbackSuffixes;
#ifdef __CC_PLATFORM_IOS
/** The iPhone RetinaDisplay suffixes to load resources.
By default it is “-hd” and “” in that order.
Only valid on iOS. Not valid for OS X.
@since v1.1
*/
@property (nonatomic,readwrite, copy, setter = setiPhoneRetinaDisplaySuffix:) NSString *iPhoneRetinaDisplaySuffix;
/*
@since v1.1
*/
@property (nonatomic,readwrite, copy, setter = setiPhone5RetinaDisplaySuffix:) NSString *iPhone5RetinaDisplaySuffix;
/** The iPad suffixes to load resources.
By default it is “-ipad”, “-hd”, “”, in that order.
Only valid on iOS. Not valid for OS X.
@since v1.1
*/
@property (nonatomic,readwrite, copy, setter = setiPadSuffix:) NSString *iPadSuffix;
/** Sets the iPad Retina Display suffixes to load resources.
By default it is “-ipadhd”, “-ipad”, “-hd”, “”, in that order.
Only valid on iOS. Not valid for OS X.
@since v2.0
*/
@property (nonatomic,readwrite, copy, setter = setiPadRetinaDisplaySuffix:) NSString *iPadRetinaDisplaySuffix;
#elif defined(__CC_PLATFORM_MAC)
/** The Mac suffixes to load resources.
By default it is “-mac”, “” in that order.
Only valid on OS X. Not valid for iOS.
@since v2.1
*/
@property (nonatomic,readwrite, copy, setter = setMacSuffix:) NSString *macSuffix;
/** The Mac Retina Display suffixes to load resources.
By default it is “-machd”, “-mac”, “” in that order.
Only valid on OS X. Not valid for iOS.
@since v2.1
*/
@property (nonatomic,readwrite, copy, setter = setMacRetinaDisplaySuffix:) NSString *macRetinaDisplaySuffix;
#endif // __CC_PLATFORM_MAC
/** returns the shared file utils instance */
+(CCFileUtils*) sharedFileUtils;
/** Purge cached entries.
Will be called automatically by the Director when a memory warning is received
*/
-(void) purgeCachedEntries;
/** Returns the fullpath of an filename.
If in iPhoneRetinaDisplay mode, and a RetinaDisplay file is found, it will return that path.
If in iPad mode, and an iPad file is found, it will return that path.
Examples:
* In iPad mode: “image.png” -> “/full/path/image-ipad.png” (in case the -ipad file exists)
* In iPhone RetinaDisplay mode: “image.png” -> “/full/path/image-hd.png” (in case the -hd file exists)
* In iPad RetinaDisplay mode: “image.png” -> “/full/path/image-ipadhd.png” (in case the -ipadhd file exists)
*/
-(NSString*) fullPathFromRelativePath:(NSString*) relPath;
/** Returns the fullpath of an filename including the resolution of the image.
If in RetinaDisplay mode, and a RetinaDisplay file is found, it will return that path.
If in iPad mode, and an iPad file is found, it will return that path.
Examples:
* In iPad mode: “image.png” -> “/full/path/image-ipad.png” (in case the -ipad file exists)
* In iPhone RetinaDisplay mode: “image.png” -> “/full/path/image-hd.png” (in case the -hd file exists)
* In iPad RetinaDisplay mode: “image.png” -> “/full/path/image-ipadhd.png” (in case the -ipadhd file exists)
* In Mac RetinaDisplay mode: “image.png” -> “/full/path/image-hd.png” (in case the -hd file exists)
If an iPad file is found, it will set resolution type to kCCResolutioniPad
If a RetinaDisplay file is found, it will set resolution type to kCCResolutionRetinaDisplay
*/
-(NSString*) fullPathFromRelativePath:(NSString*)relPath resolutionType:(ccResolutionType*)resolutionType;
#ifdef __CC_PLATFORM_IOS
/** removes the suffix from a path
* On iPhone RetinaDisplay it will remove the -hd suffix
* On iPad it will remove the -ipad suffix
* On iPad RetinaDisplay it will remove the -ipadhd suffix
Only valid on iOS. Not valid for OS X.
@since v0.99.5
*/
-(NSString *)removeSuffixFromFile:(NSString*) path;
/** Returns whether or not a given path exists with the iPhone RetinaDisplay suffix.
Only available on iOS. Not supported on OS X.
@since v1.1
*/
-(BOOL) iPhoneRetinaDisplayFileExistsAtPath:(NSString*)filename;
/** Returns whether or not a given path exists with the iPhone RetinaDisplay suffix.
Only available on iOS. Not supported on OS X.
@since v1.1
*/
-(BOOL) iPhone5RetinaDisplayFileExistsAtPath:(NSString*)filename;
/** Returns whether or not a given filename exists with the iPad suffix.
Only available on iOS. Not supported on OS X.
@since v1.1
*/
-(BOOL) iPadFileExistsAtPath:(NSString*)filename;
/** Returns whether or not a given filename exists with the iPad RetinaDisplay suffix.
Only available on iOS. Not supported on OS X.
@since v2.0
*/
-(BOOL) iPadRetinaDisplayFileExistsAtPath:(NSString*)filename;
#elif defined(__CC_PLATFORM_MAC)
/** Returns whether or not a given filename exists with the Mac RetinaDisplay suffix.
Only available on OS X. Not supported on iOS
@since v2.1
*/
-(BOOL) macRetinaDisplayFileExistsAtPath:(NSString*)filename;
/** Returns whether or not a given filename exists with the Mac RetinaDisplay suffix.
Only available on OS X. Not supported on iOS
@since v2.1
*/
-(BOOL) macFileExistsAtPath:(NSString*)filename;
#endif // __CC_PLATFORM_MAC
@end
#ifdef __cplusplus
extern “C” {
#endif
/** loads a file into memory.
the caller should release the allocated buffer.
@returns the size of the allocated buffer
@since v0.99.5
*/
NSInteger ccLoadFileIntoMemory(const char *filename, unsigned char **out);
#ifdef __cplusplus
}
#endif
.m
/*
* cocos2d for iPhone: http://www.cocos2d-iphone.org
*
* Copyright (c) 2008-2010 Ricardo Quesada
* Copyright (c) 2011 Zynga Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#import “CCFileUtils.h”
#import “../CCConfiguration.h”
#import “../ccMacros.h”
#import “../ccConfig.h”
#import “../ccTypes.h”
#ifdef __CC_PLATFORM_IOS
enum {
kCCiPhone,
kCCiPhoneRetinaDisplay,
kCCiPhone5RetinaDisplay,
kCCiPad,
kCCiPadRetinaDisplay,
};
#elif __CC_PLATFORM_MAC
enum {
kCCMac,
kCCMacRetinaDisplay,
};
#endif
#pragma mark – Helper free functions
NSInteger ccLoadFileIntoMemory(const char *filename, unsigned char **out)
{
NSCAssert( out, @”ccLoadFileIntoMemory: invalid ‘out’ parameter”);
NSCAssert( &*out, @”ccLoadFileIntoMemory: invalid ‘out’ parameter”);
size_t size = 0;
FILE *f = fopen(filename, “rb”);
if( !f ) {
*out = NULL;
return -1;
}
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
*out = malloc(size);
size_t read = fread(*out, 1, size, f);
if( read != size ) {
free(*out);
*out = NULL;
return -1;
}
fclose(f);
return size;
}
#pragma mark – CCCacheValue
@interface CCCacheValue : NSObject
{
NSString *fullpath_;
ccResolutionType resolutionType_;
}
@property (nonatomic, readwrite, retain) NSString *fullpath;
@property (nonatomic, readwrite ) ccResolutionType resolutionType;
@end
@implementation CCCacheValue
@synthesize fullpath = fullpath_, resolutionType = resolutionType_;
-(id) initWithFullPath:(NSString*)path resolutionType:(ccResolutionType)resolutionType
{
if( (self=[super init]) )
{
self.fullpath = path;
self.resolutionType = resolutionType;
}
return self;
}
- (void)dealloc
{
[fullpath_ release];
[super dealloc];
}
@end
#pragma mark – CCFileUtils
@interface CCFileUtils()
-(NSString *) removeSuffix:(NSString*)suffix fromPath:(NSString*)path;
-(BOOL) fileExistsAtPath:(NSString*)string withSuffix:(NSString*)suffix;
-(NSInteger) runningDevice;
@end
@implementation CCFileUtils
@synthesize fileManager=fileManager_, bundle=bundle_;
@synthesize enableFallbackSuffixes = enableFallbackSuffixes_;
#ifdef __CC_PLATFORM_IOS
@synthesize iPhoneRetinaDisplaySuffix = iPhoneRetinaDisplaySuffix_;
@synthesize iPhone5RetinaDisplaySuffix = iPhone5RetinaDisplaySuffix_;
@synthesize iPadSuffix = iPadSuffix_;
@synthesize iPadRetinaDisplaySuffix = iPadRetinaDisplaySuffix_;
#elif defined(__CC_PLATFORM_MAC)
@synthesize macSuffix = macSuffix_;
@synthesize macRetinaDisplaySuffix = macRetinaDisplaySuffix_;
#endif // __CC_PLATFORM_IOS
+ (id)sharedFileUtils
{
static dispatch_once_t pred;
static CCFileUtils *fileUtils = nil;
dispatch_once(&pred, ^{
fileUtils = [[self alloc] init];
});
return fileUtils;
}
-(id) init
{
if( (self=[super init])) {
fileManager_ = [[NSFileManager alloc] init];
fullPathCache_ = [[NSMutableDictionary alloc] initWithCapacity:30];
removeSuffixCache_ = [[NSMutableDictionary alloc] initWithCapacity:30];
bundle_ = [[NSBundle mainBundle] retain];
enableFallbackSuffixes_ = NO;
#ifdef __CC_PLATFORM_IOS
iPhoneRetinaDisplaySuffix_ = @”-hd”;
iPhone5RetinaDisplaySuffix_ = @”-568h”;
iPadSuffix_ = @”-ipad”;
iPadRetinaDisplaySuffix_ = @”-ipadhd”;
#elif defined(__CC_PLATFORM_MAC)
macRetinaDisplaySuffix_ = @”-machd”;
macSuffix_ = @”-mac”;
#endif // __CC_PLATFORM_IOS
}
return self;
}
-(void) purgeCachedEntries
{
[fullPathCache_ removeAllObjects];
[removeSuffixCache_ removeAllObjects];
}
- (void)dealloc
{
[fileManager_ release];
[bundle_ release];
[fullPathCache_ release];
[removeSuffixCache_ release];
#ifdef __CC_PLATFORM_IOS
[iPhoneRetinaDisplaySuffix_ release];
[iPhone5RetinaDisplaySuffix_ release];
[iPadSuffix_ release];
[iPadRetinaDisplaySuffix_ release];
#elif defined(__CC_PLATFORM_MAC)
[macRetinaDisplaySuffix_ release];
[macSuffix_ release];
#endif // __CC_PLATFORM_MAC
[super dealloc];
}
-(NSString*) pathForResource:(NSString*)resource ofType:(NSString *)ext inDirectory:(NSString *)subpath
{
return [bundle_ pathForResource:resource
ofType:ext
inDirectory:subpath];
}
-(NSString*) getPath:(NSString*)path forSuffix:(NSString*)suffix
{
NSString *newName = path;
// only recreate filename if suffix is valid
if( suffix && [suffix length] > 0)
{
NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
NSString *name = [pathWithoutExtension lastPathComponent];
// check if path already has the suffix.
if( [name rangeOfString:suffix].location == NSNotFound ) {
NSString *extension = [path pathExtension];
if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
{
// All ccz / gz files should be in the format filename.xxx.ccz
// so we need to pull off the .xxx part of the extension as well
extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
}
newName = [pathWithoutExtension stringByAppendingString:suffix];
newName = [newName stringByAppendingPathExtension:extension];
} else
CCLOGWARN(@”cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.”, name, suffix);
}
NSString *ret = nil;
// only if it is not an absolute path
if( ! [path isAbsolutePath] ) {
// pathForResource also searches in .lproj directories. issue #1230
NSString *imageDirectory = [path stringByDeletingLastPathComponent];
// If the file does not exist it will return nil.
ret = [self pathForResource:[newName lastPathComponent]
ofType:nil
inDirectory:imageDirectory];
}
else if( [fileManager_ fileExistsAtPath:newName] )
ret = newName;
if( ! ret )
CCLOGINFO(@”cocos2d: CCFileUtils: file not found: %@”, [newName lastPathComponent] );
return ret;
}
-(NSString*) fullPathFromRelativePath:(NSString*)relPath resolutionType:(ccResolutionType*)resolutionType
{
NSAssert(relPath != nil, @”CCFileUtils: Invalid path”);
CCCacheValue *value = [fullPathCache_ objectForKey:relPath];
if( value ) {
*resolutionType = value.resolutionType;
return value.fullpath;
}
// Initialize to non-nil
NSString *ret = @”";
NSInteger device = [self runningDevice];
#ifdef __CC_PLATFORM_IOS
// iPad HD ?
if( device == kCCiPadRetinaDisplay ) {
ret = [self getPath:relPath forSuffix:iPadRetinaDisplaySuffix_];
*resolutionType = kCCResolutioniPadRetinaDisplay;
}
// iPad ?
if( device == kCCiPad || (enableFallbackSuffixes_ && !ret) ) {
ret = [self getPath:relPath forSuffix:iPadSuffix_];
*resolutionType = kCCResolutioniPad;
}
// iPhone HD ?
if( device == kCCiPhone5RetinaDisplay || (enableFallbackSuffixes_ && !ret) ) {
ret = [self getPath:relPath forSuffix:iPhone5RetinaDisplaySuffix_];
*resolutionType = kCCResolutioniPhone5RetinaDisplay;
}
// iPhone HD ?
if( device == kCCiPhoneRetinaDisplay || (enableFallbackSuffixes_ && !ret) ) {
ret = [self getPath:relPath forSuffix:iPhoneRetinaDisplaySuffix_];
*resolutionType = kCCResolutioniPhoneRetinaDisplay;
}
// If it is not Phone HD, or if the previous “getPath” failed, then use iPhone images.
if( device == kCCiPhone || !ret )
{
ret = [self getPath:relPath forSuffix:@""];
*resolutionType = kCCResolutioniPhone;
}
#elif defined(__CC_PLATFORM_MAC)
if( device == kCCMacRetinaDisplay ) {
ret = [self getPath:relPath forSuffix:macRetinaDisplaySuffix_];
*resolutionType = kCCResolutionMacRetinaDisplay;
}
if( device == kCCMac || (enableFallbackSuffixes_ && !ret) ) {
ret = [self getPath:relPath forSuffix:macSuffix_];
*resolutionType = kCCResolutionMac;
}
// Not found ? Try with empty “” suffix.
if( !ret )
{
ret = [self getPath:relPath forSuffix:@""];
*resolutionType = kCCResolutionMac;
}
#endif // __CC_PLATFORM_MAC
if( ! ret ) {
CCLOGWARN(@”cocos2d: Warning: File not found: %@”, relPath);
ret = relPath;
}
value = [[CCCacheValue alloc] initWithFullPath:ret resolutionType:*resolutionType];
[fullPathCache_ setObject:value forKey:relPath];
[value release];
return ret;
}
-(NSString*) fullPathFromRelativePath:(NSString*) relPath
{
ccResolutionType ignore;
return [self fullPathFromRelativePath:relPath resolutionType:&ignore];
}
#pragma mark CCFileUtils – Suffix
// XXX: Optimization: This should be called only once
-(NSInteger) runningDevice
{
NSInteger ret=-1;
#ifdef __CC_PLATFORM_IOS
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if( CC_CONTENT_SCALE_FACTOR() == 2 )
ret = kCCiPadRetinaDisplay;
else
ret = kCCiPad;
}
else
{
if( CC_CONTENT_SCALE_FACTOR() == 2 )
{
if (([[UIScreen mainScreen] bounds].size.height == 568) || ([[UIScreen mainScreen] bounds].size.width == 568))
{
ret = kCCiPhone5RetinaDisplay;
} else {
ret = kCCiPhoneRetinaDisplay;
}
} else {
ret = kCCiPhone;
}
}
#elif defined(__CC_PLATFORM_MAC)
// XXX: Add here support for Mac Retina Display
ret = kCCMac;
#endif // __CC_PLATFORM_MAC
return ret;
}
-(NSString *) removeSuffix:(NSString*)suffix fromPath:(NSString*)path
{
// quick return
if( ! suffix || [suffix length] == 0 )
return path;
NSString *name = [path lastPathComponent];
// check if path already has the suffix.
if( [name rangeOfString:suffix].location != NSNotFound ) {
CCLOGINFO(@”cocos2d: Filename(%@) contains %@ suffix. Removing it. See cocos2d issue #1040″, path, suffix);
NSString *newLastname = [name stringByReplacingOccurrencesOfString:suffix withString:@""];
NSString *pathWithoutLastname = [path stringByDeletingLastPathComponent];
return [pathWithoutLastname stringByAppendingPathComponent:newLastname];
}
// suffix was not removed
return nil;
}
-(NSString*) removeSuffixFromFile:(NSString*) path
{
NSString *withoutSuffix = [removeSuffixCache_ objectForKey:path];
if( withoutSuffix )
return withoutSuffix;
// Initial value should be non-nil
NSString *ret = @”";
NSInteger device = [self runningDevice];
#ifdef __CC_PLATFORM_IOS
if( device == kCCiPadRetinaDisplay )
ret = [self removeSuffix:iPadRetinaDisplaySuffix_ fromPath:path];
if( device == kCCiPad || (enableFallbackSuffixes_ && !ret) )
ret = [self removeSuffix:iPadSuffix_ fromPath:path];
if( device == kCCiPhoneRetinaDisplay || (enableFallbackSuffixes_ && !ret) )
ret = [self removeSuffix:iPhoneRetinaDisplaySuffix_ fromPath:path];
if( device == kCCiPhone5RetinaDisplay || (enableFallbackSuffixes_ && !ret) )
ret = [self removeSuffix:iPhone5RetinaDisplaySuffix_ fromPath:path];
if( device == kCCiPhone || !ret )
ret = path;
#elif defined(__CC_PLATFORM_MAC)
if( device == kCCMacRetinaDisplay )
ret = [self removeSuffix:macRetinaDisplaySuffix_ fromPath:path];
if( device == kCCMac|| !ret )
ret = [self removeSuffix:macSuffix_ fromPath:path];
#endif // __CC_PLATFORM_MAC
if( ret )
[removeSuffixCache_ setObject:ret forKey:path];
return ret;
}
-(BOOL) fileExistsAtPath:(NSString*)relPath withSuffix:(NSString*)suffix
{
NSString *fullpath = nil;
// only if it is not an absolute path
if( ! [relPath isAbsolutePath] ) {
// pathForResource also searches in .lproj directories. issue #1230
NSString *file = [relPath lastPathComponent];
NSString *imageDirectory = [relPath stringByDeletingLastPathComponent];
fullpath = [bundle_ pathForResource:file
ofType:nil
inDirectory:imageDirectory];
}
if (fullpath == nil)
fullpath = relPath;
NSString *path = [self getPath:fullpath forSuffix:suffix];
return ( path != nil );
}
#ifdef __CC_PLATFORM_IOS
-(BOOL) iPhoneRetinaDisplayFileExistsAtPath:(NSString*)path
{
CCLOG(@”iPhoneRetinaDisplayFileExistsAtPath iPhoneRetinaDisplayFileExistsAtPath iPhoneRetinaDisplayFileExistsAtPath”);
return [self fileExistsAtPath:path withSuffix:iPhoneRetinaDisplaySuffix_];
}
-(BOOL) iPhone5RetinaDisplayFileExistsAtPath:(NSString*)path
{
CCLOG(@”iPhone5RetinaDisplayFileExistsAtPath iPhone5RetinaDisplayFileExistsAtPath iPhone5RetinaDisplayFileExistsAtPath”);
return [self fileExistsAtPath:path withSuffix:iPhone5RetinaDisplaySuffix_];
}
-(BOOL) iPadFileExistsAtPath:(NSString*)path
{
return [self fileExistsAtPath:path withSuffix:iPadSuffix_];
}
-(BOOL) iPadRetinaDisplayFileExistsAtPath:(NSString*)path
{
return [self fileExistsAtPath:path withSuffix:iPadRetinaDisplaySuffix_];
}
#elif defined(__CC_PLATFORM_MAC)
-(BOOL) macRetinaDisplayFileExistsAtPath:(NSString*)path
{
return [self fileExistsAtPath:path withSuffix:macRetinaDisplaySuffix_];
}
-(BOOL) macFileExistsAtPath:(NSString*)path
{
return [self fileExistsAtPath:path withSuffix:macSuffix_];
}
#endif // __CC_PLATFORM_MAC
@end
I don’t see anything about iPhone 5 support it’s only the default-568h@2.png but if I start this project it uses 2 dark stripes
@devil:
the templates from v2.1-beta2 should install the Default-568h@2x.png files. If not, it is a bug.
[b]isRelativeAnchorPoint_[/b] was replaced by [b]!ignoreAnchorPointForPosition_[/b]
But there is no info about that in the Changelog.
Has been added suffix support for iPhone 5 on github?
I’m porting a Cocos2d game (which works great with Cocos2d 2.1b2) to Mac OS X. I’m running into a crash with CCLabelTTF that I can’t figure out. Maybe it’s a bug in the Mac code in the latest version?
My code calls CCLabelTTF labelWithString, like this:
CCLabelTTF *popoverText = [CCLabelTTF labelWithString:@"KEEP TRYING" fontName:WRONG_ANSWER_FONT fontSize:popoverFontSize dimensions:CGSizeMake( popoverWidth, popoverTextHeight) hAlignment:kCCTextAlignmentCenter lineBreakMode:kCCLineBreakModeClip];
It works great on iOS. But in Mac OS it says “Thread 5 CVDisplayLink: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0×0)” when it gets to the following line of code in initWithString:(NSString*)string dimensions:(CGSize)dimensions hAlignment:(CCTextAlignment)hAlignment vAlignment:(CCVerticalTextAlignment)vAlignment attributedString:(NSAttributedString*)stringWithAttributes:
// Get actual rendered dimensions
NSRect boundingRect = [stringWithAttributes boundingRectWithSize:NSSizeFromCGSize(dimensions) options:NSStringDrawingUsesLineFragmentOrigin];
Everything looks pretty good:
POTSize is (width=512, height=64)
dimensions is (width=311, height=40)
Any ideas? I just tried some different strings, since it’s a fixed string @”KEEP TRYING” — I tried @”z” and that worked. I wonder if it crashes if the text doesn’t fit. Many of the font sizes in the code are too big while I’m getting things working for Mac OS. So it seems that when text is too big to fit it’s crashing on that call. Maybe specifically if the text is too tall to fit then it crashes.
Yes, iPhone 5 support is something I had been waiting for.
I just tried the update to 2.1 beta2 by removing my libs folders and copying over new ones. Everything compiled OK, but my screen is blank when I run my game. I get this output on the console:
2012-10-14 08:32:28.815 7 Bridges[2165:c07] cocos2d: cocos2d v2.1-beta2
2012-10-14 08:32:28.815 7 Bridges[2165:c07] cocos2d: Using Director Type:CCDirectorDisplayLink
OpenGL error 0×0506 in -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 563
OpenGL error 0×0502 in -[CCGLView swapBuffers] 283
2012-10-14 08:32:33.734 7 Bridges[2165:c07] cocos2d: surface size: 1136×640
Maybe I missed some steps in the upgrade.
-Zack
Riq, I just got latest version of v2.1 beta2 and from a blank iOS template new project I get the error “Use of undeclared identifier ‘_ccCurrentBoundTexture’ on the ccGLStateCache.m file (lines 155 and 156). I’m on Lion 10.7.5 with XCode 4.5.1
@itlgames: strange… I will take a look at it. Which template did you instantiate ?
Just the default iOS templare, not box2d or chipmunk or javascript.
Hello riq
I have updated cocos2d to v2.1beta for iphone support. But I found my game works slowly on iPhone 4 & iPod Touch 4.(Fps is 30 ~ 40 when it’s 50 ~ 60 with cocos2d v1.x). I have checked my code carefully. No issues are found.
I searched in the forum. Someones have the same trouble with me. Someones say OpenGL 2.0 causes the issue.
I don’t know how to resolve the question. Help me. Thanks for your hard work for cocos2d!
@sea:
check the debug console. Probably you will need to enable the cache.
Edit ccConfig.h an set: CC_ENABLE_GL_STATE_CACHE = 1
Riq, I found the issue I posted before, it’s on the ccGLStateCache.m, you define the array _ccCurrentBoundTexture only if CC_ENABLE_GL_STATE_CACHE = 1, by default is 0, so on this file on line 153 you have a function ccGLDeleteTextureN that tries to access the _ccCurrentBoundTexture even if CC_ENABLE_GL_STATE_CACHE = 0 (so giving the undefined error). If I set CC_ENABLE_GL_STATE_CACHE = 1 then the error is gone:
void ccGLDeleteTextureN( GLuint textureUnit, GLuint textureId )
{
if( _ccCurrentBoundTexture[ textureUnit ] == textureId )
_ccCurrentBoundTexture[ textureUnit ] = -1;
glDeleteTextures(1, &textureId );
}
@riq
October 16, 2012 at 10:01 am
@sea:
check the debug console. Probably you will need to enable the cache.
Edit ccConfig.h an set: CC_ENABLE_GL_STATE_CACHE = 1
I have modified by your way. The Fps is 30 ~ 40 yet.
@itlgames:
thanks. fixed.