swiftのspritekitを使ってかんたんなゲームを作っているプログラミング初心者です。
最初のメニューシーンでは画面中央が(0.0)座標なのですが、画面遷移で次のシーンにすると画面左下を中心(0.0)とする座標系に何故か変わってしまいます。
GameViewControllerからMenuSceneへは問題なく表示できますが、MenuSceneからGameSceneを表示させようとすると座標系が完全にずれてしまいます。ノードの表示はGCPointでしています。何かアドバイスをいただけると嬉しいです。
view
1 2 override func viewDidLoad() { 3 super.viewDidLoad() 4 5 6 // Load 'GameScene.sks' as a GKScene. This provides gameplay related content 7 // including entities and graphs. 8 if let scene = GKScene(fileNamed: "menuScene") { 9 10 11 12 // Get the SKScene from the loaded GKScene 13 if let sceneNode = scene.rootNode as! menuScene? { 14 15 16 // Set the scale mode to scale to fit the window 17 sceneNode.scaleMode = .aspectFill 18 19 // Present the scene 20 if let view = self.view as! SKView? { 21 22 view.presentScene(sceneNode) 23 24 view.ignoresSiblingOrder = true 25 26 view.showsFPS = true 27 view.showsNodeCount = true 28 } 29 } 30 } 31 } 32
```menuScene.swift override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch:AnyObject in touches{ let location = touch.location(in:self) let touchedNode=self.nodes(at: location) //タッチされた場所を取得 //このlocationの位置は画面左上が起点になっている… print(location) if location.y>(frame.midY)*0.41{ let nextScene = GameScene() nextScene.size = self.size let transition = SKTransition.crossFade(withDuration: 0.3) nextScene.scaleMode = .aspectFit self.view?.presentScene(nextScene, transition: transition) } } }
```GameScene.swift class GameScene: SKScene { //⭐衝突判定用 static let bluetenCategory: UInt32 = 0b1000 static let blackBarCategory: UInt32 = 0b0010 //sprite3 // static let finalCategory: UInt32 = 0b0100//ファルコンチューブ static let ecgCategory: UInt32 = 0b0001 override func sceneDidLoad() { // self.addChild(playSound2) physicsWorld.contactDelegate = self self.backgroundColor = SKColor.black addCharacter() // startECG() preStartECG() blackBar() ueBar() bluePoint() self.run(playSound3) setupScoreLabel() }
あなたの回答
tips
プレビュー