質問編集履歴
1
全体のコードを載せました
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,91 @@
|
|
8
8
|
|
9
9
|
```swift
|
10
10
|
|
11
|
+
import SpriteKit
|
12
|
+
|
13
|
+
import GameplayKit
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
class GameScene: SKScene, SKPhysicsContactDelegate {
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
var red: SKSpriteNode!
|
22
|
+
|
23
|
+
var blue: SKSpriteNode!
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
let redMask:UInt32 = 0b0001
|
28
|
+
|
29
|
+
let blueMask:UInt32 = 0b0010
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
override func didMove(to view: SKView) {
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
self.scaleMode = .aspectFill
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
let border = SKPhysicsBody(edgeLoopFrom: self.frame)
|
42
|
+
|
43
|
+
border.friction = 0
|
44
|
+
|
45
|
+
self.physicsBody = border
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
self.red = SKSpriteNode(imageNamed: "red")
|
50
|
+
|
51
|
+
self.red.scale(to: CGSize(width: 150, height: 150))
|
52
|
+
|
53
|
+
self.red.position = CGPoint(x: 0, y: frame.height / 4)
|
54
|
+
|
55
|
+
self.red.physicsBody = SKPhysicsBody(circleOfRadius: self.red.frame.height / 2)
|
56
|
+
|
57
|
+
self.red.physicsBody?.categoryBitMask = redMask
|
58
|
+
|
59
|
+
self.red.physicsBody?.contactTestBitMask = 0b1111
|
60
|
+
|
61
|
+
self.red.physicsBody?.affectedByGravity = false
|
62
|
+
|
63
|
+
self.red.physicsBody?.restitution = 1.0
|
64
|
+
|
65
|
+
self.red.physicsBody?.linearDamping = 0.0
|
66
|
+
|
67
|
+
self.red.physicsBody?.friction = 0.0
|
68
|
+
|
69
|
+
addChild(self.red)
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
self.blue = SKSpriteNode(imageNamed: "blue")
|
74
|
+
|
75
|
+
self.blue.scale(to: CGSize(width: 100, height: 100))
|
76
|
+
|
77
|
+
self.blue.position = CGPoint(x: frame.width / 4 - 30, y: -frame.height / 4)
|
78
|
+
|
79
|
+
self.blue.physicsBody = SKPhysicsBody(circleOfRadius: self.blue.frame.height / 2)
|
80
|
+
|
81
|
+
self.blue.physicsBody?.categoryBitMask = blueMask
|
82
|
+
|
83
|
+
self.blue.physicsBody?.contactTestBitMask = 0b0001
|
84
|
+
|
85
|
+
self.blue.physicsBody?.affectedByGravity = false
|
86
|
+
|
87
|
+
addChild(self.blue)
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
self.red.physicsBody?.applyImpulse(CGVector(dx: 500, dy: 500))
|
92
|
+
|
93
|
+
}
|
94
|
+
|
11
|
-
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
95
|
+
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
12
96
|
|
13
97
|
let location = touches.first!.location(in: self)
|
14
98
|
|
@@ -20,6 +104,16 @@
|
|
20
104
|
|
21
105
|
}
|
22
106
|
|
107
|
+
}
|
108
|
+
|
109
|
+
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
23
117
|
```
|
24
118
|
|
25
119
|
|