-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContents.swift
More file actions
38 lines (29 loc) · 1.21 KB
/
Contents.swift
File metadata and controls
38 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//: Playground - noun: a place where people can play
import UIKit
import SpriteKit
import XCPlayground
let sceneView =
SKView(frame: CGRect(x: 0, y: 0, width: 480, height: 320))
let scene = SKScene(size: CGSize(width: 480, height: 320))
sceneView.showsFPS = true
sceneView.showsPhysics = true
scene.physicsWorld.gravity = CGVector(dx: 0, dy: 0)
scene.physicsBody = SKPhysicsBody(edgeLoopFromRect: scene.frame)
sceneView.presentScene(scene)
XCPShowView("My Scene", view: sceneView)
let spaceShip = SKSpriteNode(imageNamed: "spaceship")
spaceShip.name = "spaceship"
spaceShip.position =
CGPoint(x: scene.size.width * 0.25, y: scene.size.height * 0.50)
spaceShip.physicsBody = SKPhysicsBody(circleOfRadius: spaceShip.size.width/2)
scene.addChild(spaceShip)
spaceShip.runAction(
SKAction.sequence([
SKAction.scaleTo(0.1, duration: 2),
SKAction.rotateByAngle(2, duration: 2),
SKAction.moveBy(CGVector(dx: -25, dy: -25), duration: 2),
SKAction.rotateByAngle(3, duration: 2),
SKAction.scaleTo(0.3, duration: 1),
SKAction.applyImpulse(CGVector(dx: 350, dy: 125), atPoint: CGPoint(x: 0, y: 0), duration: 20)
])
)