如何在SpriteKit中显示警报视图

编程入门 行业动态 更新时间:2024-10-10 23:16:02
本文介绍了如何在SpriteKit中显示警报视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望在我的SpriteKit游戏中显示UIAlertView(说没有足够的硬币来选择项目)。我在我的(仅)ViewController 中设置了 UIAlertView * alertView; 属性并对其进行了初始化。

I wish to display UIAlertView in my SpriteKit game (saying there is not enough coins to select an item). I have set UIAlertView *alertView; property in my (only) ViewController and initialized it.

但是我无法从我的场景中访问它(尝试调用公共方法,但它不起作用)。

However I can't access this from my Scene (tried to call a public method but it didn't work).

如何从场景中访问我的ViewController及其属性?

How can I access my ViewController and its properties form the scene?

推荐答案

关于如何访问ViewController (和它的属性)来自你的SKScene或任何SKNode,我会在创建后在这些SKNode中保存一个指针。

As to how to access the ViewController (and its properties) from your SKScene or any SKNode, I would save a pointer inside those SKNodes after creation.

@interface YourScene : SKScene @property (weak,nonatomic) UIViewController * presentingViewController; @end // inside the ViewController YourScene * scene = [YourScene new]; scene.presentingViewController = self; [skView presentScene:scene];

标题问题的答案:在SpriteKit中显示alertViews

您不必在ViewController中放置 alertView 属性;你可以把它放在你的SKScene,或任何你喜欢的地方。您甚至不必设置委托,但如果您想让您的SKScene子类符合 UIAlertViewDelegate 协议。

An answer to your title question: Displaying alertViews in SpriteKit

You don't have to put the alertView property in your ViewController; you can just put it in your SKScene, or wherever you like. You don't even have to set a delegate, but if you want to just have your SKScene subclass conform to the UIAlertViewDelegate protocol.

@interface YourNode : SKNode<UIAlertViewDelegate> - (void) displayAlert; @end // ... @implementation YourNode - (void) displayAlert { UIAlertView * alertView = [UIAlertView alloc] initWithTitle:@"Your title" message:@"Your message is this message" delegate:self cancelButtonTitle:@"Cancel me" otherButtonTitles:@"Whatever", nil]; [alertView show]; } @end

更多推荐

如何在SpriteKit中显示警报视图

本文发布于:2023-11-27 16:11:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   警报   如何在   SpriteKit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!