ios - 在 SWIFT 中使用参数调用另一个类中的 GameScene

标签 ios swift xcode sprite-kit skscene

我很沮丧现在要让它工作 2 个小时!!!

我有两个类 GameSceneSetup,我想在我的 Setup 中打印 GameScene 的框架类。

class Setup {

   static var gameScene = GameScene()
   static func whatsFrame() {
      print("\(gameScene.frame.maxX)")
}


class GameScene: SKScene {

   override func didMove(to view: SKView) {
      print("\(self.frame.maxX)")
      Setup.whatsFrame()
   }
}

本应如此简单,但控制台给出了以下答案:

320.0 and -0.0

最佳答案

尝试通过参数将 GameScene 帧信息传递给您的 Setup 类,例如:

在您的 GameScene didMove() 函数中:

        Setup.whatsFrame(frameOfGameSceneMaxX: self.frame.maxX,
                            frameOfGameSceneMinX: self.frame.minX)

在你的 Setup 类中:

   static func whatsFrame(frameOfGameSceneMaxX: CGFloat, frameOfGameSceneMinX: CGFloat) {
       print("\(frameOfGameSceneMaxX)")
       print("\(frameOfGameSceneMinX)")
}

关于ios - 在 SWIFT 中使用参数调用另一个类中的 GameScene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46744471/

相关文章:

php - 我需要使用 PHP 在电子邮件中从我的应用程序中获取一个数组

ios - 单击 uibutton 时使用应用程序调用

swift - 创建 Swift 框架(重新访问)

arrays - 在 swift 中向数组添加函数

ios - Core Animation to flash score(UILabel)

ios - Sentry 错误 - IndexSizeError : The index is not in the allowed range

ios - Rightalignment UITextfield 的光标在输入空格后向左移动

ios - 如何创建具有不同页面大小的 UIScrollView(页面对齐、弹跳)

swift - TableView 未加载数据

objective-c - 获取 NSArray 长度/计数 - Objective C