cocos2d custom dialog box with yes/no choices
As of now, I can only do:
`UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:@"New Game"];
[dialog setMessage:@"Are you sure you want to start a new game? This will overwrite your current game."];
[dialog addButtonWithTitle:@"Yes"];
[dialog addButtonWithTitle:@"No"];
[dialog show];
[dialog release];
...
- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonInde开发者_开发百科x
{
if(buttonIndex==0) {
gametype = 1;
[[CCDirector sharedDirector] replaceScene:[CCTransitionCrossFade transitionWithDuration:1 scene:[GameScene node]]];
}
}
`
The bad thing is that the dialog box really does not mix in with the whole theme of the application.
Is there a way I can customize or create a dialogue box that appears?
I've heard that customizing UIAlertView has been very controversial to the point of being rejected form the app store. I don't think I should go with this method. Do you have any suggestions/code I can use?
PS: I have a dialogue box image and yes/no buttons already done.
If you already have a dialog box and YES/NO buttons, then I would just add the dialog box the the layer a sprite with the YES/NO buttons overlaid as CCMenuItemImage(s). Then you can have the no button just hide the visibility of the menu and the dialog box and the yes button replace the scene.
dialogBox = [CCSprite spriteWithFile:@"dialogBox.png"];
CCMenuItemImage *yesButton = [CCMenuItemImage itemFromNormalImage:@"yes.png" selectedImage:@"yes.png" target:self selector:@selector(yesSelector)]
CCMenuItemImage *noButton = [CCMenuItemImage itemFromNormalImage:@"no.png" selectedImage:@"no.png" target:self selector:@selector(noSelector)]
Then in your noSelector method you can just hide the dialog box and in your yesSelector just replace the scene.
精彩评论