【问题标题】:Calling GameScene in another Class with parameter in SWIFT在 SWIFT 中使用参数在另一个类中调用 GameScene
【发布时间】:2017-10-14 12:19:53
【问题描述】:

现在让这个工作 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

【问题讨论】:

    标签: ios swift xcode sprite-kit skscene


    【解决方案1】:

    尝试通过参数将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)")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      • 1970-01-01
      • 2023-04-11
      • 2021-05-21
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      相关资源
      最近更新 更多