2017-08-01 20 views
-1

チュートリアルの後、次のコードで現在のコイン数を表示させます。新しいハイスコアを保存して、表示用に出力するにはどうすればよいですか?ハイスコアを保存して出力する

私はどのように出力/表示するかを試すことができます。まず保存する方法を検討するだけです。

import SpriteKit 

class HUD: SKNode { 
var textureAtlas = SKTextureAtlas(named:"HUD") 
var coinAtlas = SKTextureAtlas(named: "Environment") 
// An array to keep track of the hearts: 
var heartNodes:[SKSpriteNode] = [] 
// An SKLableNode to print the coin score: 
let coinCountText = SKLabelNode(text: "000000") 
let restartButton = SKSpriteNode() 
let menuButton = SKSpriteNode() 
func createHudNodes(screenSize:CGSize) { 
    let cameraOrigin = CGPoint(x: screenSize.width/2, 
           y: screenSize.height/2) 
    // Create the coin counter: 
    // First, create and position a bronze coin icon: 
    let coinIcon = SKSpriteNode(texture: coinAtlas.textureNamed("coin-bronze")) 
    // Size and position the coin icon: 
    let coinPosition = CGPoint(x: -cameraOrigin.x + 23, y: cameraOrigin.y - 23) 
    coinIcon.size = CGSize(width: 26, height: 26) 
    coinIcon.position = coinPosition 
    // Configure the coin text label: 
    coinCountText.fontName = "AvenirNext-HeavyItalic" 
    let coinTextPosition = CGPoint(x: -cameraOrigin.x + 41, y: coinPosition.y) 
    coinCountText.position = coinTextPosition 
    // These two properties allow you to align the 
    // text relative to the SKLabelNode's position: 
    coinCountText.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.left 
    coinCountText.verticalAlignmentMode = SKLabelVerticalAlignmentMode.center 
    // Add the text label and coin icon to the HUD: 
    self.addChild(coinCountText) 
    self.addChild(coinIcon) 
} 

func setCoinCountDisplay(newCoinCount:Int) { 
    // We can use the NSNumberFormatter class to pad 
    // leading 0's onto the coin count: 
    let formatter = NumberFormatter() 
    let number = NSNumber(value: newCoinCount) 
    formatter.minimumIntegerDigits = 6 
    if let coinStr = formatter.string(from: number) { 
     // Update the label node with the new count: 
     coinCountText.text = coinStr 
    } 
} 

}

+0

でも*関連*列の中に多くの関連[質問とanwsers](https://stackoverflow.com/search?q=SpriteKit+save+high+score)があります。 – vadian

+0

iOS向けにこのHUDライブラリをhttps://github.com/shubh10/JustHUDで試してみてください –

答えて

0

あなたは、少量のデータを格納するためUserDefaultsの助けを使用することができます。

UserDefaults.standard.set(00, forKey: "HighScore") 
関連する問題