[Swift] 등속 직선 동작(SpriteKit 사용)
환경은 Xcode6-Beta4입니다.
Game에서 새 항목을 만들고 Game Technology에서 SpriteKit를 선택합니다.
GameScene.swift에 다음 내용을 쓰면 완성됩니다.
GameScene.swift
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch in touches {
let location = touch.locationInNode(self)
// 赤い正方形を作成
let square = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake(60, 60))
square.position = location
square.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(60, 60))
// 速度を設定
square.physicsBody.velocity = CGVectorMake(0,200)
// 重力を無視する
square.physicsBody.affectedByGravity = false
// 空気抵抗を無視する
square.physicsBody.linearDamping = 0
self.addChild(square)
}
}
override func update(currentTime: CFTimeInterval) {}
}
Reference
이 문제에 관하여([Swift] 등속 직선 동작(SpriteKit 사용)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/mochizukikotaro/items/1ddebb0618129d368858텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)