Skip to content

Instantly share code, notes, and snippets.

@syou007
Last active February 27, 2017 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syou007/e7cb056e4cb349d8afa3d819a68f2f7d to your computer and use it in GitHub Desktop.
Save syou007/e7cb056e4cb349d8afa3d819a68f2f7d to your computer and use it in GitHub Desktop.
SwiftでOpenGLを使ったゲームを作成する方法 ref: http://qiita.com/syou007/items/794cc681da5c82e44101
- (void) loadStringsFile:(NSString*) file
{
// Load default localization dictionary
NSString* path = [[CCFileUtils sharedFileUtils] fullPathForFilename:file];
// Load strings file
NSDictionary* ser = [NSDictionary dictionaryWithContentsOfFile:path];
// Check that format of file is correct
NSAssert([[ser objectForKey:@"fileType"] isEqualToString:@"SpriteBuilderTranslations"], @"Invalid file format for SpriteBuilder localizations");
// Check that file version is correct
NSAssert([[ser objectForKey:@"fileVersion"] intValue] == 1, @"Translation file version is incompatible with this reader");
// Load available languages
NSArray* languages = [ser objectForKey:@"activeLanguages"];
// Determine which language to use
NSString* userLanguage = NULL;
NSArray* preferredLangs = [NSLocale preferredLanguages];
for (NSString* preferredLang in preferredLangs)
{
// now loop thru languages from our cocosbuilder
for (NSString *localizedLanguage in languages)
{
// doing range of string as we might have en-GB set in our phone and that will match our en from the activeLanguages
if ([preferredLang rangeOfString:localizedLanguage].location != NSNotFound)
{
userLanguage = localizedLanguage;
break;
}
}
if (userLanguage != NULL) {
break;
}
}
// Create dictionary for translations
_translations = [[NSMutableDictionary alloc] init];
// Load translations
if (userLanguage != NULL)
{
NSArray* translations = [ser objectForKey:@"translations"];
for (NSDictionary* translation in translations)
{
NSString* key = [translation objectForKey:@"key"];
NSString* value = [(NSDictionary*)[translation objectForKey:@"translations"] objectForKey:userLanguage];
if (key != NULL && value != NULL)
{
[_translations setObject:value forKey:key];
}
}
}
}
-(void)draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform
{
void (*Func)(id, SEL) = (void(*)(id, SEL)) objc_msgSend;
Func(self, _drawSelector);
}
ld: warning: object file (/.../Build/Products/Debug-iphonesimulator/libcocos2d.a(IOSVersion.o)) was built for newer iOS version (9.3) than being linked (8.0)
ld: warning: object file (/.../Build/Products/Debug-iphonesimulator/libcocos2d.a(IOSVersion.o)) was built for newer iOS version (9.3) than being linked (8.0)
The culprit is the minimum deployment target for the ObjectAL library -
In Xcode delve into the cocos2d project -> external -> ObjectAL project:
Goto build settings and search for 'deployment target'
and set the value to be <= your main project minimum deployment target.
- (id) init
{
if(nil != (self = [super init]))
{
#if __CC_PLATFORM_IOS
NSString* versionStr = [[UIDevice currentDevice] systemVersion];
unichar ch = [versionStr characterAtIndex:0];
version = (float)(ch - '0');
if(ch < '0' || ch > '9' || [versionStr characterAtIndex:1] != '.')
{
// NSLog(@"Error: %s: Cannot parse iOS version string \"%@\"", __PRETTY_FUNCTION__, versionStr);
// Version 10以上
version = (float)(ch - '0') * 10 + (float)([versionStr characterAtIndex:1] - '0');
}
float multiplier = 0.1f;
NSUInteger vLength = [versionStr length];
for(NSUInteger i = 2; i < vLength; i++)
{
ch = [versionStr characterAtIndex:i];
if(ch >= '0' && ch <= '9')
{
version += (ch - '0') * multiplier;
multiplier /= 10;
}
else if('.' != ch)
{
break;
}
}
#else
version = 5;
#endif
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment