xcode - Cocos2d How to Switch Scenes -


how switch scenes in cocos2d? have main class, "hellowworldlayer.h/.m" , can't seem switch scenes correctly. have tried :

[[ccdirector shareddirector] replacescene:[race node]]; //and [[ccdirector shareddirector] replacescene:[race scene]]; 

i put break point in , can see going new scene button added new scene isn't showing up. creating button correctly. adding screen in new scene this:

 [self addchild:menu]; 

i took of code holloworldlayer.m/.h , copied new scene (class) unable transition correctly. new xcode , cocos2d sorry if simple.

race.m

#import "race.h" #import "intermediary.h"  @implementation race   +(ccscene *) scene{     // 'scene' autorelease object.     ccscene *scene = [ccscene node];      // 'layer' autorelease object.     race *layer = [race node];      // add layer child scene     [scene addchild: layer];      // return scene     return scene; }  -(id) init{      if( (self=[super init]) ) {          nslog(@"racing!");         cclabelttf *startlbl = [cclabelttf labelwithstring:@"start" fontname:@"marker felt" fontsize:20];         ccmenuitemlabel *startmenu = [ccmenuitemlabel itemwithlabel:startlbl block:^(id sender) {             nslog(@"i have been pushed!");         }];         startmenu.position = ccp(50,50);         ccmenu *menu = [ccmenu menuwithitems:startmenu, nil];         [self addchild:menu];       }     return self; }   @end 

your code worked me.

here sample: download

use transition better look.

[[ccdirector shareddirector] replacescene:[cctransitionfade transitionwithduration:1.0 scene:[race scene] ]]; 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -