swiftのスプライトキットのサンプルになれば。
やってること
・イメージを取り込んで、物理特性を持たせる
・ボタンクリックでイメージをジャンプさせる
ほとんどobjective-cと変わらないですね。
import SpriteKit
class GameScene: SKScene {
let Jump : CGFloat = 400.0
let imageWidth : CGFloat = 30.0
let FloarWidth : CGSize = CGSizeMake(500, 500)
override func didMoveToView(view: SKView) {
/* Setup your scene here */
let iorin = SKSpriteNode(imageNamed:"minase-iori0020")
iorin.xScale = 0.1
iorin.yScale = 0.1
iorin.position = CGPoint(x:CGRectGetMidX(self.frame),y:CGRectGetMidY(self.frame));
iorin.name = "iori"
let body = SKPhysicsBody(circleOfRadius:imageWidth)
iorin.physicsBody = body
self.addChild(iorin)
let floor = SKSpriteNode(imageNamed:"minase-iori0020")
floor.xScale = 0.3
floor.yScale = 0.3
floor.position = CGPoint(x:CGRectGetMidX(self.frame),y:CGRectGetMinY(self.frame));
floor.name = "floor"
let body2 = SKPhysicsBody(rectangleOfSize:FloarWidth)
body2.affectedByGravity = false
body2.dynamic = false
body2.contactTestBitMask = 1
floor.physicsBody = body2
self.addChild(floor)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
self.childNodeWithName("iori").physicsBody.velocity.dy = Jump
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
self.childNodeWithName("floor").position =CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMinY(self.frame));
}
}