开发者

Where should I go from here? (Cocos2D+UIKit)

开发者 https://www.devze.com 2023-04-09 16:02 出处:网络
Currently I have this code in my UIViewController: //Cocos2D methods -(id) init { if((self=[super init]))

Currently I have this code in my UIViewController:

//Cocos2D methods
-(id) init {
    if((self=[super init]))
    {
        CCScene *scene = [CCScene node];
        CCLayer *layer = [CCLayer node];
        [scene addChild:layer];
        [[CCDirector sharedDirector] runWithScene:scene];
        [[CCDirector sharedDirector] setDisplayFPS:NO];
        [self performSelector:@selector(cocosgameLoop:) withObject:nil afterDelay:1/60.0f];
    }
    return self;
}
- (void)cocosgameLoop:(ccTime)dT {
    //Check for collisions here and add gravity, etc....
}
- (void)viewDidUnload {
    [super viewDidUnload];
    [[CCDirector sharedDirector] end];
}
//

My view controller is somewhat Objective-C code, but I want to add Cocos2D to the UIView. I think the code above is initializing it, but I am not sure. Also should the CCScene have its own class dedicated to everything that goes on in the scene? if so how would I do that? I know these are a lot of questions, but my game is very similar to 开发者_Go百科Doodle Jump and I need to know where to go from the current state I am in. Does anyone have any ideas/tips?

Thanks!


performSelector will call the cocosgameLoop only once. You will want to call CCDirector startAnimation, and then schedule updates in your cocos2d nodes.

My Learn Cocos2D book (2nd Edition) explains how to add and setup Cocos2D in a UIKit view (regular iPhone) app.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号