Swift3.0
GameScene.swift
//
// GameScene.swift
// SpriteKit028
//
// Created by Misato Morino on 2016/09/20.
// Copyright © 2016年 Misato Morino. All rights reserved.
//
import SpriteKit
class GameScene: SKScene {
private var unHideAction : SKAction!
private var rect : SKShapeNode!
override func didMove(to view: SKView) {
// Nodeを非表示させるアクションを作る.
unHideAction = SKAction.hide()
// 赤い四角形を作る.
rect = SKShapeNode(rectOf: CGSize(width: 50.0, height: 50.0))
rect.fillColor = UIColor.red
rect.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
self.addChild(rect)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
// アクションを実行させる.
rect.run(unHideAction)
}
}
Swift 2.3
GameScene.swift
//
// GameScene.swift
// SpriteKit028
//
// Created by Misato Morino on 2016/09/20.
// Copyright © 2016年 Misato Morino. All rights reserved.
//
import SpriteKit
class GameScene: SKScene {
private var unHideAction : SKAction!
private var rect : SKShapeNode!
override func didMoveToView(view: SKView) {
// Nodeを非表示させるアクションを作る.
unHideAction = SKAction.hide()
// 赤い四角形を作る.
rect = SKShapeNode(rectOfSize: CGSizeMake(50.0, 50.0))
rect.fillColor = UIColor.redColor()
rect.position = CGPointMake(self.frame.midX, self.frame.midY)
self.addChild(rect)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
// アクションを実行させる.
rect.runAction(unHideAction)
}
}
2.3と3.0の差分
didMoveToView(view: SKView) から didMove(to view: SKView) に変更
runAction から run に変更
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.