Macbook pro (OS X EI Captian 10.11.5)
Xcode 7.3.1
1. 參考文獻比較 Sprite Kit 與 Unity
2. 開啟 New Project (Game template)
新專案包含Spaceship圖檔(Assets.xcassets)
3. GameScene.swift
//
// GameScene.swift
// SWSpriteHello
//
// Created by Jou CS on 2016/8/3.
// Copyright (c) 2016年 Jou CS. All rights reserved.
//
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
//-- 2016.8.3 加入 Hello World! 標籤控制項
let myLabel = SKLabelNode(fontNamed:"Chalkduster")
myLabel.text = "Hello, World!"
myLabel.fontSize = 45
myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
self.addChild(myLabel)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
// -- 2016.8.3 Click 加入 自轉的Spaceship
for touch in touches {
let location = touch.locationInNode(self)
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.xScale = 0.5
sprite.yScale = 0.5
sprite.position = location
let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)
sprite.runAction(SKAction.repeatActionForever(action))
self.addChild(sprite)
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}4. 執行專案
沒有留言:
張貼留言