Hi currently I am loading my game with a menu with a couple of buttons. What i want to happen is when the user presses the button it will move to a different scene which will be the game. Depending on the button the user presses will load a different tilemap file for the game.
I have a game world view where currently it reads in just one tilemap file, I was wondering how i would go about changing the tilemap file depending on which button the user presses.
In my menu file I use this method once button 1 is pressed:
- (void)button1Tapped:(id)sender {
[_label setString:@"Last button: 1"];
[self.worldLevel setLevel:1];
CCScene *scene = [CCScene node];
[scene addChild:[GameWorld node]];
[[CCDirector sharedDirector] replaceScene:[CCFlipAngularTransition transitionWithDuration:1.2f scene:scene]];
}
is using the function [self.worldLevel setLevel:1]; correct?
in my world level file i have this:
-(void)setLevel:(int)newLevel {
if(newLevel == 1){
levelNum = 1;
}
else if(newLevel == 2){
levelNum = 2;
}
}
and the init statement uses the value of levelNum to determine which tilemap to load:
if(levelNum == 1) {
self.tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"Level1.tmx"];
}
else if(levelNum == 2) {
self.tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"Level2.tmx"];
}
but it crashes and the problem is that a tilemap hasn't been loaded.
Am I doing it correctly by loading the file based on the user input in menu to load the correct tmx file in the game world init?