简体   繁体   中英

Spritekit Swift game menu zooms in the screen

I have created a game, in its final stages, using SpriteKit and Swift. I have created a menu for it in another scene called MenuScene.swift, and i've placed a button so that when you click it, it leads to the GameScene.swift file in which my game is stored in. However, whenever I click the button to go from the menu to starting the game, it zooms in my game a lot and ruins the interface altogether. How can I fix this? Here is my relevant view controller coding:

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)
    }

Heres my menuscene:

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
    }
}
self.scene?.size = self.view!.bounds.size

在didMoveToView中的GameScene.swift中

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM