Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
Swift SKLabel赢得';我没有出现_Swift_Sprite Kit - Fatal编程技术网

Swift SKLabel赢得';我没有出现

Swift SKLabel赢得';我没有出现,swift,sprite-kit,Swift,Sprite Kit,我正在用精灵工具包制作一款飞禽类游戏。游戏运行得很好,但我正在尝试一种方法来为游戏打分,所以我设置了一个变量和SKLabel,每当管道穿过屏幕一半时,该变量和SKLabel就会自动添加。但是,我无法让标签显示任何帮助,这是我的代码: // flappy rainbow sheep // // Created by Heather Arnold on 3/3/15. // Copyright (c) 2015 ian arnold. All rights reserved. // impo

我正在用精灵工具包制作一款飞禽类游戏。游戏运行得很好,但我正在尝试一种方法来为游戏打分,所以我设置了一个变量和SKLabel,每当管道穿过屏幕一半时,该变量和SKLabel就会自动添加。但是,我无法让标签显示任何帮助,这是我的代码:

//  flappy rainbow sheep
//
//  Created by Heather Arnold on 3/3/15.
//  Copyright (c) 2015 ian arnold. All rights reserved.
//

import SpriteKit

class GameScene: SKScene {

var bird = SKSpriteNode()
var pipeUpTexture = SKTexture()
var pipeDownTexture = SKTexture()
var PipeMoveAndRemove = SKAction()
let pipeGap = 225.0
var score: Int = 0
var scoreLabel: SKLabelNode = SKLabelNode(fontNamed:"System-Bold")




override func didMoveToView(view: SKView) {
    /* Setup your scene here */
    score = 0

    //Physics
    self.physicsWorld.gravity = CGVectorMake(0.0, -10.0);

    //Bird
    var BirdTexture = SKTexture(imageNamed:"flappysheep")
    BirdTexture.filteringMode = SKTextureFilteringMode.Nearest

    bird = SKSpriteNode(texture: BirdTexture)
    bird.setScale(0.5)
    bird.position = CGPoint(x: self.frame.size.width * 0.35, y: self.frame.size.height * 0.6)

    scoreLabel.position.x = 50
    scoreLabel.position.y = view.bounds.height - 50

    scoreLabel.text = "0"
    scoreLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Left

    scoreLabel.hidden = false
    self.addChild(scoreLabel)

    bird.physicsBody = SKPhysicsBody(circleOfRadius:bird.size.height/4.0);
    bird.physicsBody?.dynamic = true
    bird.physicsBody?.allowsRotation = false

    self.addChild(bird)

    //off screen


    //Ground
    var groundTexture = SKTexture(imageNamed:"rainbowobstacle")
    var sprite = SKSpriteNode(texture: groundTexture)
    sprite.setScale(2.0)
    sprite.position = CGPointMake(self.size.width/2.0, sprite.size.height/2.0)

    self.addChild(sprite)

    var ground = SKNode()

    ground.position = CGPointMake(0, groundTexture.size().height)
    ground.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(self.frame.size.width, groundTexture.size().height * 2.0))
    ground.physicsBody?.dynamic = false
    self.addChild(ground)

    //Pipes

    //create the pipes
    pipeUpTexture = SKTexture(imageNamed:"rainbowpipe")
    pipeDownTexture = SKTexture(imageNamed:"rainbowpipe")

    //move pipes
    let distanceToMove = CGFloat(self.frame.size.width + 2.0 * pipeUpTexture.size().width)
    let movePipes = SKAction.moveByX(-2500, y: 0.0, duration: NSTimeInterval(0.01 * distanceToMove))
    let removePipes = SKAction.removeFromParent()

    PipeMoveAndRemove = SKAction.sequence([movePipes, removePipes])

    //spwan pipes
    let spawn = SKAction.runBlock({() in self.spawnPipes()})
    let delay = SKAction.waitForDuration(NSTimeInterval(0.2))
    let spawnThenDelay = SKAction.sequence([spawn, delay])
    let spawnThenDelayForever = SKAction.repeatActionForever(spawnThenDelay)
    self.runAction(spawnThenDelayForever)

    let pipeUp = SKSpriteNode(texture:pipeUpTexture)

    if (pipeUp.position.x + (pipeUp.size.width / 2) < self.view!.bounds.size.width / 2)
    {
        score++

    }
    scoreLabel.hidden = false


}



func spawnPipes(){
    let pipePair = SKNode()
    pipePair.position = CGPointMake(self.frame.size.width + pipeUpTexture.size().width * 2, 0)
    pipePair.zPosition = -10

    let height = UInt32(self.frame.size.height / 4)
    let y = arc4random() % height + height

    let pipeDown = SKSpriteNode(texture:pipeDownTexture)
    pipeDown.setScale(2.0)
    pipeDown.position = CGPointMake(0.0, CGFloat(y) + pipeDown.size.height + CGFloat(pipeGap))

    pipeDown.physicsBody = SKPhysicsBody(rectangleOfSize:pipeDown.size)
    pipeDown.physicsBody?.dynamic = false
    pipePair.addChild(pipeDown)

    let pipeUp = SKSpriteNode(texture:pipeUpTexture)
    pipeUp.setScale(2.0)
    pipeUp.position = CGPointMake(0.0, CGFloat(y))

    pipeUp.physicsBody = SKPhysicsBody(rectangleOfSize: pipeUp.size)
    pipeUp.physicsBody?.dynamic = false
    pipePair.addChild(pipeUp)

    pipePair.runAction(PipeMoveAndRemove)
    self.addChild(pipePair)





}





class GameScene: SKScene {

    let bird = SKSpriteNode()
    var gameOver = false

    override init(size: CGSize) {
        super.init(size: size)

        self.bird.position = CGPoint(x: 0, y: 0)
        self.addChild(self.bird)

    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func endGame(){
        // restart the game
        let gameScene = GameScene(size: self.size)
        self.view!.presentScene(gameScene)
    }

    override func update(currentTime: NSTimeInterval) {


        // our bird doesnt intersect the frame,
        // we use gameOver bool so we dont call endGame more than once
        if !self.frame.intersects(self.bird.frame) && !self.gameOver{
            self.gameOver = true
            self.endGame()
        }

    }

}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    /* Called when a touch begins */

    for touch: AnyObject in touches {

        let location = touch.locationInNode(self)

        bird.physicsBody?.velocity = CGVectorMake(0, 0)
        bird.physicsBody?.applyImpulse(CGVectorMake(0, 8))


    }
}

override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */
}
}
//flappy彩虹羊
//
//希瑟·阿诺德于2015年3月3日创作。
//版权所有(c)2015伊恩·阿诺德。版权所有。
//
进口SpriteKit
类游戏场景:SKScene{
var bird=SKSpriteNode()
var pipeUpTexture=SKTexture()
var pipeDownTexture=SKTexture()
var PipeMoveAndRemove=SKAction()
让管道间隙=225.0
变量分数:Int=0
var scoreLabel:SKLabelNode=SKLabelNode(字体名称:“系统粗体”)
覆盖func didMoveToView(视图:SKView){
/*在这里设置场景*/
分数=0
//物理学
self.physicsWorld.gravity=CGVectorMake(0.0,-10.0);
//鸟
var BirdTexture=SKTexture(图像名为:“flappysheep”)
BirdTexture.filteringMode=SKTextureFilteringMode.Nearest
bird=SKSpriteNode(纹理:BirdTexture)
鸟类。设置刻度(0.5)
bird.position=CGPoint(x:self.frame.size.width*0.35,y:self.frame.size.height*0.6)
scoreLabel.position.x=50
scoreLabel.position.y=view.bounds.height-50
scoreLabel.text=“0”
scoreLabel.horizontalAlignmentMode=SKLabelHorizontalAlignmentMode.Left
scoreLabel.hidden=false
self.addChild(scoreLabel)
bird.physicsBody=SKPhysicsBody(圆圈半径:bird.size.height/4.0);
bird.physicsBody?.dynamic=true
bird.physicsBody?.allowsRotation=false
self.addChild(鸟)
//屏幕外
//地面
var groundTexture=SKTexture(图像名为:“彩虹障碍物”)
var sprite=SKSpriteNode(纹理:groundTexture)
sprite.setScale(2.0)
sprite.position=CGPointMake(self.size.width/2.0,sprite.size.height/2.0)
self.addChild(精灵)
var ground=SKNode()
ground.position=CGPointMake(0,groundTexture.size().height)
ground.physicsBody=SKPhysicsBody(矩形尺寸:CGSizeMake(self.frame.size.width,groundTexture.size().height*2.0))
地面。physicsBody?动态=假
self.addChild(地面)
//管道
//创建管道
pipeUpTexture=SKTexture(图像名为:“彩虹管”)
pipeDownTexture=SKTexture(图像名为:“彩虹管”)
//移动管道
let distanceToMove=CGFloat(self.frame.size.width+2.0*pipeUpTexture.size().width)
让movePipes=SKAction.moveByX(-2500,y:0.0,持续时间:NSTimeInterval(0.01*distanceToMove))
让removePipes=SKAction.removeFromParent()
PipeMoveAndRemove=SKAction.sequence([movePipes,removepippes])
//spwan管道
让spawn=SKAction.runBlock({()在self.spawnpippes()中)
让延迟=SKAction.waitForDuration(NSTimeInterval(0.2))
让spawnThenDelay=SKAction.sequence([spawn,delay])
让spawnThenDelayForever=SKAction.repeatActionForever(spawnThenDelay)
self.runAction(永远)
let pipeUp=SKSpriteNode(纹理:pipeUpTexture)
if(pipeUp.position.x+(pipeUp.size.width/2)
您的标签可能被其他图像覆盖。尝试将SKLabelNode
zPosition
属性设置为更高的值。可能是900左右。

尝试将标签的Z位置设置为1

scoreLabel.zPosition = 1
这将使该节点出现,即使另一个节点经过它。 以下是另外两个可能对您有所帮助的功能:

scoreLabel.color = UIColor.blackColor()//set color to black - you can use any almost color here 
scoreLabel.fontSize = 32//changes font size to make label bigger/smaller

我试过你说的,但还是没有结果there@eman885113-可能是找不到指定的字体。尝试使用不同的字体。有点像“Helvetica”。哦,忘了在问题@sangony中标记你了