- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Swift 2 在 XCode 7 中制作游戏。我有一个变量,我想从开始屏幕(它是一个 UIViewController)传递到游戏场景(它是一个 SKScene)。我希望玩家在 UIView 中选择一个角色并在 SKScene 中使用它。我还希望 SKScene 中的分数显示在作为 UIView 的游戏结束屏幕中。我看过在两个 UIViewController 之间和两个 SKScenes 之间传递数据的教程,但它们都不适用于这种情况。
如何将变量从 UIViewController 传递到 SKScene(反之亦然)?
最佳答案
如果您还没有找到答案,我确实找到了一种方法。我在做一些非常相似的事情。
在我的例子中,我有一个 UIView,它从我的场景中作为暂停菜单被调用。我使类名和变量名更加模糊,以便它们也适用于您的情况。
class MyView: UIView {
var scene: MyScene!
var button: UIButton!
init(frame: CGRect, scene: MyScene){
super.init(frame: frame)
self.scene = scene
//initialize the button
button.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "buttonTapped"))
}
func buttonTapped(){
self.removeFromSuperview() // this removes my menu from the scene
scene.doTheThing() // this calls the method on my scene
}
这是我场景的相关部分。
class MyScene: SKScene {
func doTheThing(){
//this is a function on the scene. You can pass any variable you want through the function.
}
}
在您的情况下,听起来第一个屏幕是 UIView,第二个屏幕是 SKScene。
您可能想先制作您的 SKScene,暂停它,然后在场景前面添加 UIView。选择角色后,您可以移除 UIView 并将您的角色添加到场景中。
我希望这能回答您的问题。如果它不让我知道。
关于ios - 将变量从 UIViewController 传递到 SK Scene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32672522/
为什么使用 java 和“du -sk”计算目录的已用空间不同?以及“du -sk”的确切 java 替代方案是什么? PFB Java 代码, final String location =
我在阅读某些方法的名称时确实遇到了一些困难,因为 Apple 没有提供其缩写的附录,对于该方法:SKPaymentQueue,SK 代表什么? 最佳答案 它代表StoreKit。请注意您用于获取该类的
更新: 每个请求我都有 NSLogged [[event touchesForView:self.view] count] 和 touches count 并得到 2 和 1 当故障发生时,那么事件似
使用以下代码,我尝试加载数据集并对其执行 NB 算法。 from sklearn.naive_bayes import MultinominalNB import pandas as pd impor
我有一个 SKAction,如果触摸屏幕上的某个区域,它就会运行一个操作。但是我无法让 SKanimate 仅运行 SKarray 一次(即两个操作),它似乎运行了大约 4 次。 count 参数似乎
我正在使用 SK map 。我可以在 Location 上显示注释,但 map 不会以该位置为中心,而是以某个不同的位置为中心,并且 animateToZoom 无法平滑缩放。任何帮助将不胜感激。 最
在警告消息中使用 OpenSSL 中的库时: warning: pointer type mismatch in conditional expression [enabled by default]
我想调整图像大小。我的图像包含特定值 [0, 1, 2, 7, 9]。调整大小后,会引入新值,例如 5 等。我想阻止这种情况。 我目前正在使用 scikit图像大小调整功能。我已经尝试了所有插值标志,
我在 MySQL 中有一个简单的 posts 表,其中有一个 POST_ID 作为 SK(代理键)。对原始帖子 ID 的回复存储在同一个表的 PARENT_POST_ID 列中,但我想执行以下逻辑:
我有超过六个与 Facebook 集成的应用程序。他们都使用旧的 Facebook iOS SDK(在其 SDK 的单点登录版本之前)。去年左右一切都进展顺利。现在,所有应用程序都会报告错误:“操作链
我让球每 3 秒生成一次,如果分数增加,我希望球生成得更快。问题是我的生成率在 4 秒内保持不变,并且在我的分数增加时不会改变。感谢m8s的帮助 var spawnRate : TimeInt
我有一个名为 Cell 的 SKNode 子类。我设置了所有物理体,它们正确地碰撞。但是,didBeginContact() 函数位于 GameScene 中,我需要它位于 Cell 中,因为我想调用
import pandas import math from csv import reader import sys import numpy as np from pandas.plotting
我在本地计算机上创建了一个 sklearn 模型。然后我把它上传到谷歌存储上。我使用相同的模型在 AI Platform 中创建了模型和版本。它正在用于在线预测。现在我想执行批量预测并将数据存储到大查
当用户点击“购买”按钮时,我的应用程序向 StoreKit 发出 addPayment。之后,我想显示带有“请稍候”和事件指示器的警报 View 。但是,SK 也可以显示警报 View 。有什么办法可
我正在使用 Swift 2 在 XCode 7 中制作游戏。我有一个变量,我想从开始屏幕(它是一个 UIViewController)传递到游戏场景(它是一个 SKScene)。我希望玩家在 UIVi
我正在尝试通过创建自己的游戏(应用程序)来学习 Swift,但我遇到了问题。 我有一个 SKSpriteNode 用作游戏的背景。这是我制作的图像。我的问题是我的背景不会填满 View ,所以我在节点
我非常需要你的帮助。所以我是 XCODE 的 SpriteKit 的新手,我刚刚开始使用这个机制。我目前有一个背景图像和一个位于中心的 Sprite 。 问题 Sprite 在屏幕上水平移动,这正是我
我正在尝试使用适用于 Android 的 SK map SDK,但我遇到了一些问题。我已按照本网站的指导进行操作:http://developer.skobbler.com/getting-start
我正在创建一个基于瓦片 map 的 2d 游戏,这是我自己做的第一个程序,所以请在您花时间回答我时考虑一下 :) 我已经构建了 UI 和一张小 map ,我终于让我的角色可以用箭头键移动了。但是我找不
我是一名优秀的程序员,十分优秀!