cocos2d 自定义对话框,带有是/否选项

发布于 2024-11-27 13:31:08 字数 819 浏览 0 评论 0原文

截至目前,我只能这样做:

`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)buttonIndex
{
    if(buttonIndex==0) {
        gametype = 1;
        [[CCDirector sharedDirector] replaceScene:[CCTransitionCrossFade transitionWithDuration:1 scene:[GameScene node]]];
    }
}
`

糟糕的是,该对话框确实没有与应用程序的整个主题融为一体。

有没有办法可以自定义或创建出现的对话框?

我听说自定义 UIAlertView 一直存在很大争议,甚至被应用商店拒绝。我认为我不应该采用这种方法。您有我可以使用的建议/代码吗?

PS:我有一个对话框图像和是/否按钮已经完成。

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)buttonIndex
{
    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.

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

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

发布评论

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

评论(1

夜司空 2024-12-04 13:31:08

如果您已经有一个对话框和“是/否”按钮,那么我只需将对话框添加到精灵图层中,并将“是/否”按钮覆盖为 CCMenuItemImage。然后,您可以让“否”按钮隐藏菜单和对话框的可见性,让“是”按钮替换场景。

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)]

然后,在 noSelector 方法中,您可以隐藏对话框,而在 yesSelector 中,只需替换场景。

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.

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