Hey guys. I know how to make a UIAlertView, but I was wondering how you make one appear if a certain CCBitMapFontAtlas is tapped. I want the view to show before the other page displays. Thanks.
UIAlertView Help
(10 posts) (4 voices)-
Posted 1 year ago #
-
I found from this post http://www.cocos2d-iphone.org/forum/topic/991#post-5966 that you should use something like this.
- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0) {
//do stuff
}
}The only problem is that that post is from a year ago. Also, can someone explain what will go in the if statement that will make the scene change depending on which button the user picks?
Thanks again.
Posted 1 year ago # -
It doesn't really matter if it was from a year ago, the code from that post still works the same.
Posted 1 year ago # -
Here is how i do it...
-(void) alertView:(UIAlertView *) alert clickedButtonAtIndex: (NSUInteger) buttonIndex { if (buttonIndex == 0) { [[CCDirector sharedDirector] replaceScene:[CCPageTurnTransition transitionWithDuration:1 scene:[HelloWorld node]]]; //Change Scene } }Posted 1 year ago # -
Thanks again @xcrunner509. I have 2 choices to exit the alert view. One is entering the game, and another is going back to HelloWorldScene. Can I make two different methods, each going to the selected place? I'm assuming that
buttonIndex == 0is the first choice, andbuttonIndex == 1would be the second choice.
@Kitsune I thought maybe the code would be outdated.Posted 1 year ago # -
How can I make it so a UIAlertView shows up if a CCBitmapFontAtlas is tapped?
Posted 1 year ago # -
In the method that is called when your menu item is tapped, create your alert view, and set the delegate.
Posted 1 year ago # -
Thanks @liquidfire. So would this work?
-(void) new: (id) sender { alert = [[UIAlertView alloc] init]; [alert setDelegate:self]; [alert setTitle:@"Warning"]; [alert setMessage:@"This will overwrite any current games."]; [alert addButtonWithTitle:@"Start New Game Anyway"]; [alert addButtonWithTitle:@"Cancel"]; [alert show]; [alert release]; [[CCDirector sharedDirector] replaceScene:[CCFlipAngularTransition transitionWithDuration:1.2f scene:[GamePlay node]]]; }Posted 1 year ago # -
Right idea, wrong implementation.
1) You don't need
alertto be an instance variable. It is being deallocated at the end of the method, so any future references toalertwill just crash, unless initialized again.
2) You aren't initializingalertproperly. Well actually, what you are doing will work, but I like doing it the proper way, in case anything API-wise changes in the future.Change it to this:
-(void) new: (id) sender { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"This will overwrite any current games." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Start New Game Anyway", nil]; [alert show]; [alert release]; [[CCDirector sharedDirector] replaceScene:[CCFlipAngularTransition transitionWithDuration:1.2f scene:[GamePlay node]]]; }Posted 1 year ago # -
Thanks @liquidfire. I think I'm doing it differently because I got it from an old youtube video.
Posted 1 year ago #
Reply
You must log in to post.