scottD
scottD

Reputation: 135

Works on simulator but not on device?


I've run into a problem with a game I'm messing around with and can't figure it out.

I have a CCMenu in a class called "Map" that gives the user a choice of what game level to go to. I set a tag to each menuItem, and set the selector for all the menuItems to a method called "goToScene". In that method, I figure which level was chosen and use the sharedDirector to replace the Map scene with the appropriate level layer. I'll list the code below.

The code works fine in the simulator, but on my device (iphone 4) it freezes when I click on any of the menuItems. I've had the "works on simulator but not on device" problem before and it turned out to be a capitalization error on one of my images....so I checked all of my resources and they're good. I've also cleaned the project but no help there either.

Thanks in advance for any ideas about this.

Scott

        level= [CCSprite spriteWithFile:@"level.png"];
    CCMenuItemImage *one =[CCMenuItemImage itemFromNormalImage:@"one.png" selectedImage:@"one.png" target:self selector:@selector(goToScene:)];
    CCMenuItemImage *two= [CCMenuItemImage itemFromNormalImage:@"two.png" selectedImage:@"two.png" target:self selector:@selector(goToScene:)];
    CCMenuItemImage *three= [CCMenuItemImage itemFromNormalImage:@"three.png" selectedImage:@"three.png" target:self selector:@selector(goToScene:)];

    one.tag=1;
    two.tag=2;
    three.tag=3;

    CCMenu *menu = [CCMenu menuWithItems: one,two,three,nil];
    [menu alignItemsHorizontally];

    level.position = ccp(screenSize.width/2,screenSize.height-50);
    [self addChild:level];
    [self addChild:menu];





    [self schedule: @selector(tick:)];
}
return self;

}

And here is the method that gets called. This is where it's freezing up...

-(void)goToScene:(id)sender{

CCMenuItem *temp = (CCMenuItem *)sender;
if (temp.tag==1) {
    GameScene *scene = [[GameScene alloc] init];
    Level1 *sc = [[Level1 alloc] init];
    [scene addChild:sc];
    [[CCDirector sharedDirector]replaceScene:scene];
}
if (temp.tag==2) {
    GameScene *scene = [[GameScene alloc]init];
    Level2 *sc = [[Level2 alloc]init];
    [scene addChild:sc];
    [[CCDirector sharedDirector]replaceScene:scene];

}
if (temp.tag==3) {

    GameScene *scene = [[GameScene alloc]init];
    Level3 *sc = [[Level3 alloc]init];
    [scene addChild:sc];
    [[CCDirector sharedDirector]replaceScene:scene];
}

}

Upvotes: 0

Views: 895

Answers (2)

KDaker
KDaker

Reputation: 5909

any iOS device requires the filenames to be case sensitive but the simulator can find them if they are not the same capitalization.. so always double check the file names in your code.

Upvotes: 1

scottD
scottD

Reputation: 135

Alright...I figured it out, so I figured I'd post it in case it may help someone else. In my GameScene class I load a HUDLayer to the top of the screen in the init method, and in the HUDLayer class I have a pause button. In my code I screwed up the capitalization of the file. So it turned out to be the usual suspect for this problem...one of my resources was typed wrong and the simulator let it slide while the device wont..

Upvotes: 0

Related Questions