如何在 iPhone 的 Cocos2d 层上显示 UIAlertView?

发布于 2024-08-15 04:56:26 字数 716 浏览 3 评论 0原文

我的游戏中有一个层面。游戏结束时,我想向用户显示用于重新启动或退出游戏的 UIAlertView。但它不起作用。我还获得了委托 UIAlertViewDelegate 到图层。

有什么解决方案吗?

我的代码如下,

-(void)gameFinished{
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];

    [self unschedule:@selector(checkForCollision)];
    [self unschedule:@selector(dropObject)];
    [self stopBackgroundMusic];

    [self startNewForegroundMusic:@"GameOver" ofType:@"caf"];
    [self playForegroundMusic];

    [[Director sharedDirector] pause];
    UIAlertView *view=[[UIAlertView alloc] initWithTitle:@"Game Finished" message:@"Want to play again?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes"];
    [view show];
    [view release];
} 

I have a layer in my game. At finishing of game I want to show user an UIAlertView for restarting or quitting the game. But it is not working. I am also given the delegate UIAlertViewDelegate to layer.

Any Solutions?

My Code follows,

-(void)gameFinished{
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];

    [self unschedule:@selector(checkForCollision)];
    [self unschedule:@selector(dropObject)];
    [self stopBackgroundMusic];

    [self startNewForegroundMusic:@"GameOver" ofType:@"caf"];
    [self playForegroundMusic];

    [[Director sharedDirector] pause];
    UIAlertView *view=[[UIAlertView alloc] initWithTitle:@"Game Finished" message:@"Want to play again?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes"];
    [view show];
    [view release];
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回梦 2024-08-22 04:56:26

您的代码是否崩溃,或者只是不显示?

您在这行中确实有一个小错误,

[[UIAlertView alloc] initWithTitle:@"Game Finished"
                     message:@"Want to play again?"
                     delegate:self cancelButtonTitle:@"No"
                     otherButtonTitles:@"Yes"]

应该

[[UIAlertView alloc] initWithTitle:@"Game Finished"
                     message:@"Want to play again?"
                     delegate:self cancelButtonTitle:@"No"
                     otherButtonTitles:@"Yes", Nil]

注意:最后一个参数是变量参数,因此应该以 Nil 终止。

Does your code crash, or does it just not display?

You do have a slight error in the line

[[UIAlertView alloc] initWithTitle:@"Game Finished"
                     message:@"Want to play again?"
                     delegate:self cancelButtonTitle:@"No"
                     otherButtonTitles:@"Yes"]

This should be

[[UIAlertView alloc] initWithTitle:@"Game Finished"
                     message:@"Want to play again?"
                     delegate:self cancelButtonTitle:@"No"
                     otherButtonTitles:@"Yes", Nil]

note: the last parameter is variable argument, and thus should be Nil terminated.

两仪 2024-08-22 04:56:26

尝试在导演暂停之前显示警报视图,这可能会起作用。

Try to show the alertview before the director is pause it may work..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文