Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Spritekit Swift游戏菜单将在屏幕上放大_Ios_Swift_Sprite Kit_Swift2_Ios9 - Fatal编程技术网

Ios Spritekit Swift游戏菜单将在屏幕上放大

Ios Spritekit Swift游戏菜单将在屏幕上放大,ios,swift,sprite-kit,swift2,ios9,Ios,Swift,Sprite Kit,Swift2,Ios9,我已经创建了一个游戏,在其最后阶段,使用SpriteKit和Swift。我已经在另一个名为MenuScene.swift的场景中为它创建了一个菜单,并且我放置了一个按钮,这样当您单击它时,它将指向GameScene.swift文件,我的游戏存储在该文件中。然而,每当我点击按钮从菜单转到开始游戏时,它会放大我的游戏并破坏整个界面。我怎样才能解决这个问题?以下是我的相关视图控制器编码: class GameViewController: UIViewController { override fu

我已经创建了一个游戏,在其最后阶段,使用SpriteKit和Swift。我已经在另一个名为MenuScene.swift的场景中为它创建了一个菜单,并且我放置了一个按钮,这样当您单击它时,它将指向GameScene.swift文件,我的游戏存储在该文件中。然而,每当我点击按钮从菜单转到开始游戏时,它会放大我的游戏并破坏整个界面。我怎样才能解决这个问题?以下是我的相关视图控制器编码:

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    let sceneView = view as! SKView
    // sceneView.showsFPS = true
    // sceneView.showsNodeCount = true
    sceneView.ignoresSiblingOrder = true

    let scene = MenuScene(size: view.bounds.size)
    scene.scaleMode = .ResizeFill
    sceneView.presentScene(scene)
    }
这是我的菜单:

import Foundation
import UIKit
import SpriteKit

let buttonTexture = SKTexture(imageNamed: "play")

let button = SKSpriteNode(texture: buttonTexture)

class MenuScene: SKScene {

override func didMoveToView(view: SKView) {

    button.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))

    self.addChild(button)
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch: AnyObject in touches {

        let location = touch.locationInNode(self)

        if button.containsPoint(location) {

            startGame()

        }

    }
}

private func startGame() {
    let gameScene = GameScene(size: view!.bounds.size)
    let transition = SKTransition.fadeWithDuration(0.15)
    view!.presentScene(gameScene, transition: transition)
    gameScene.scaleMode = .AspectFill
    }
}
<代码>导入基础 导入UIKit 进口SpriteKit 让buttonTexture=SKTexture(图像名为:“播放”) let button=SKSpriteNode(纹理:buttonTexture) 类MenuScene:SKScene{ 覆盖func didMoveToView(视图:SKView){ button.position=CGPointMake(CGRectGetMidX(self.frame)、CGRectGetMidY(self.frame)) self.addChild(按钮) } 覆盖func touchesEnded(触摸:设置,withEvent事件:UIEvent?){ 用于触摸:触摸中的任何对象{ let location=touch.locationInNode(自) if按钮。containsPoint(位置){ startGame() } } } 私人func startGame(){ 让游戏场景=游戏场景(大小:view!.bounds.size) let transition=SKTransition.fadeWithDuration(0.15) view!.presentScene(游戏场景,过渡:过渡) gameScene.scaleMode=.AspectFill } }
在didMoveToView中的GameSecene.swift中

你能发布一些代码吗?@Icy你应该发布view controller中的代码,以及转换到GameSecene的代码(从MenuScene到GameSecene)。我在,但由于某种原因,一部分内容被剪切到了普通文本中。这与加载的方向
游戏场景
有关。如果你把你的模拟器转到横向,然后构建应用程序,我想这就是你想要的结果?我的模拟器在横向运行,因为我的游戏是一个平台
self.scene?.size = self.view!.bounds.size