Ios 如何制作一个UIButton来呈现我的游戏场景?(没有缩放?)

Ios 如何制作一个UIButton来呈现我的游戏场景?(没有缩放?),ios,swift,uibutton,Ios,Swift,Uibutton,当我制作了一个UIButton,并让该功能呈现游戏场景时,它只会出现一个绿色的场景,看起来像是我的一个播放器,但实际上是特写 以下是游戏场景代码: import SpriteKit class GameScene: SKScene, SKPhysicsContactDelegate{ var Score = Int() var player = SKSpriteNode(imageNamed: "player") var ScoreLabel = UILabel() override func

当我制作了一个UIButton,并让该功能呈现游戏场景时,它只会出现一个绿色的场景,看起来像是我的一个播放器,但实际上是特写

以下是游戏场景代码:

import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate{
var Score = Int()
var player = SKSpriteNode(imageNamed: "player")
var ScoreLabel = UILabel()

override func didMoveToView(view: SKView) {
    self.view?.backgroundColor = UIColor.blueColor()
    physicsWorld.contactDelegate = self
    player.physicsBody = SKPhysicsBody(rectangleOfSize: player.size)
    player.physicsBody?.affectedByGravity = false
    player.physicsBody?.categoryBitMask = PhysicsCatagory.player
    player.physicsBody?.contactTestBitMask = PhysicsCatagory.Chlorine
    player.physicsBody?.dynamic = false
    player.position = CGPointMake( self.size.width/2, self.size.height/10)
    self.addChild(player)
    var stimer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("spawnShot"), userInfo: nil, repeats: true)
    var Ctimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("spawnChlorine"), userInfo: nil, repeats: true )
    ScoreLabel.text = "\(Score)"
    ScoreLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
    ScoreLabel.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.width / 7)
    //ScoreLabel.backgroundColor = UIColor.whiteColor()
    ScoreLabel.textColor = UIColor.blackColor()
    //ScoreLabel.font = UIFont.smallSystemFontSize(30)
    self.view?.addSubview(ScoreLabel)

}

func didBeginContact(contact: SKPhysicsContact) {
    var firstBody : SKPhysicsBody = contact.bodyA
    var secondBody : SKPhysicsBody = contact.bodyB

    if ((firstBody.categoryBitMask == PhysicsCatagory.Chlorine) && (secondBody.categoryBitMask == PhysicsCatagory.Shot))   ||
    ((firstBody.categoryBitMask == PhysicsCatagory.Shot) && (secondBody.categoryBitMask == PhysicsCatagory.Chlorine)){

        collisionWithShot((firstBody.node as? SKSpriteNode)!, Shot: (secondBody.node as? SKSpriteNode)!)

    }else if ((firstBody.categoryBitMask == PhysicsCatagory.Chlorine) && (secondBody.categoryBitMask == PhysicsCatagory.player)) ||
        ((firstBody.categoryBitMask == PhysicsCatagory.player) && (secondBody.categoryBitMask == PhysicsCatagory.Chlorine)){

            collisionWithPlayer(firstBody.node as! SKSpriteNode, player: secondBody.node as! SKSpriteNode)
    }
}

func collisionWithShot (Chlorine: SKSpriteNode, Shot: SKSpriteNode){
    Chlorine.removeFromParent()
    Shot.removeFromParent()
    Score++
    ScoreLabel.text = ("Score: \(Score)")
}

func collisionWithPlayer (Chlorine: SKSpriteNode, player: SKSpriteNode){
    player.removeFromParent()
    Chlorine.removeFromParent()
    ScoreLabel.removeFromSuperview()
    self.view?.presentScene(EndScene())
}

func spawnShot(){
    var Shot = SKSpriteNode(imageNamed: "Shot")
    zPosition = -5
    Shot.size = CGSize(width: 30, height: 30)
    Shot.position = CGPointMake(player.position.x, player.position.y)
    let action = SKAction.moveToY(self.size.height + 30, duration: 0.8)
    let actionDone = SKAction.removeFromParent()
    Shot.runAction(SKAction.sequence([action, actionDone]))
    Shot.physicsBody = SKPhysicsBody(rectangleOfSize: Shot.size)
    Shot.physicsBody?.categoryBitMask = PhysicsCatagory.Shot
    Shot.physicsBody?.contactTestBitMask = PhysicsCatagory.Chlorine
    Shot.physicsBody?.affectedByGravity = false
    Shot.physicsBody?.dynamic = false
    self.addChild(Shot)
}

   var stimer:NSTimer!
    override func touchesBegan(touches: Set<NSObject>, withEvent event:     UIEvent) {
    /* Called when a touch begins */
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)
        player.position.x = location.x
    }
}

func spawnChlorine(){
    var Chlorine = SKSpriteNode(imageNamed: "Chlorine.png")
    var minValue = self.size.width / 8 
    var maxValue = self.size.width - 20
    var spawnPoint = UInt32((maxValue - minValue))
    Chlorine.position = CGPoint(x: CGFloat (arc4random_uniform (spawnPoint )) ,y: self.size.height)
    let action = SKAction.moveToY(-20, duration: 8.0)
    let actionDone = SKAction.removeFromParent()
    Chlorine.runAction(SKAction.sequence([action, actionDone]))
    Chlorine.runAction(SKAction.repeatActionForever(action))
    Chlorine.physicsBody = SKPhysicsBody(rectangleOfSize: Chlorine.size)
    Chlorine.physicsBody?.categoryBitMask = PhysicsCatagory.Chlorine
    Chlorine.physicsBody?.contactTestBitMask = PhysicsCatagory.Shot
    Chlorine.physicsBody?.affectedByGravity = false
    Chlorine.physicsBody?.dynamic = true
    self.addChild(Chlorine)
}

override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)
        player.position.x = location.x
        //player.position.y = location.y
    }
}

override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */
}
}

那么这里有什么问题呢?这个按钮显示了我的播放器的一个非常近的视图,帧速率从60下降到20 fps
//
//  EndScene.swift
//  Algae Escape
//
//  Created by Alex Walker on 8/24/15.
//  Copyright (c) 2015 Alex Walker. All rights reserved.
//

import Foundation
import SpriteKit


class EndScene : SKScene {

var restartButton : UIButton!
override func didMoveToView(view: SKView) {
    scene?.backgroundColor = UIColor.whiteColor()

    restartButton = UIButton(frame: CGRect(x: 0, y: 0, width: view.frame.size.width / 3, height: 30))
    restartButton.center = CGPoint(x: view.frame.size.width / 2, y: view.frame.size.width / 7)


    restartButton.setTitle("Restart", forState: UIControlState.Normal)
    restartButton.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
    restartButton.addTarget(self, action: Selector("Restart"), forControlEvents: UIControlEvents.TouchUpInside)
    self.view?.addSubview(restartButton)
}
func Restart(){
    self.view?.presentScene(GameScene(), transition: SKTransition.crossFadeWithDuration(0.3))
    restartButton.removeFromSuperview()        
}
}