1.初始化窗口
orride func viewDidLoad() {
super.viewDidLoad()
if let view = self.view as! SKView? {
//用来加载自己的页面
let scence = FirstScence(size:view.bounds.size)
scence.scaleMode = .AspectFill
//页面跳转
view.presentScene(scence)
}
}
2.创建文本
//SKLabelNode
let myLabel = SKLabel.init()
myLabel.text = "hello"
self.addChild(myLabel)
3.添加动作
//SKAction
let moveSequence = SKAction.sequence([])
4.界面跳转
self.view?.presentScence(scence);
5.获取当前位置
var x = myLabel.postion.x
var y = myLabel.postion.y
6.物体碰撞
spriteKit有自己的碰撞识别方法,我们只需要实现代理即可
SKPhysicsContactDelegate
override func didMoveToView(view: SKView) {
//
self.physicsWorld.contactDelegate = self
A.physicsBody?.categoryBitMask = 1
A.physicsBody?.categoryTestBitMask = 2
B.physicsBody?.categoryBitMask = 2
B.physicsBody?.categoryTestBitMask = 1
}
//发生碰撞调用
func didBeginContact(contact:SKPhysicsContact) {
}
7.删除
myLabel.romoveFromParent()