Created
January 4, 2014 16:20
-
-
Save PaulSolt/8256995 to your computer and use it in GitHub Desktop.
A wrapper around Cocos2d so that you can use it with UIKit as a view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AECocos2D.h | |
// CocosUIKitTest | |
// | |
// Created by Paul Solt on 7/4/13. | |
// Copyright (c) 2014 Paul Solt. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface AECocos2D : NSObject | |
+ (AECocos2D *)shared; | |
- (void)setupDirector; | |
- (CCGLView *)currentGLView; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AECocos2D.m | |
// CocosUIKitTest | |
// | |
// Created by Paul Solt on 7/4/13. | |
// Copyright (c) 2014 Paul Solt. All rights reserved. | |
// | |
#import "AECocos2D.h" | |
@implementation AECocos2D { | |
CCGLView *_glView; | |
} | |
static AECocos2D *sharedInstance; | |
+ (AECocos2D *)shared; | |
{ | |
if(!sharedInstance) { | |
sharedInstance = [[AECocos2D alloc] init]; | |
sharedInstance->_glView = [CCGLView viewWithFrame:[[UIScreen mainScreen] bounds] | |
pixelFormat:kEAGLColorFormatRGBA8 //kEAGLColorFormatRGB565 | |
depthFormat:0 //GL_DEPTH_COMPONENT24_OES | |
preserveBackbuffer:NO | |
sharegroup:nil | |
multiSampling:NO | |
numberOfSamples:0]; | |
[sharedInstance->_glView setMultipleTouchEnabled:YES]; | |
[sharedInstance setupDirector]; | |
[sharedInstance->_glView setFrame:[[UIScreen mainScreen] bounds]]; | |
} | |
return sharedInstance; | |
} | |
- (void)setupDirector | |
{ | |
CCDirectorIOS *director = (CCDirectorIOS *) [CCDirector sharedDirector]; | |
[director setView:_glView]; | |
[director enableRetinaDisplay:YES]; | |
// director.wantsFullScreenLayout = YES; // Not on iOS 7 | |
[director setDisplayStats:YES]; | |
[director setAnimationInterval:1.0/60]; | |
} | |
- (CCGLView *)currentGLView { | |
return _glView; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
// Call this right here, before anything else. Need to set up the director ASAP | |
[AECocos2D shared]; | |
// Other setup code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment