-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameScene.swift
78 lines (62 loc) · 2.44 KB
/
GameScene.swift
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// GameScene.swift
// MagicTouch
//
// Created by Valerie on 18.03.23.
//
import SpriteKit
import GameplayKit
class GameScene: SKScene {
//private var label : SKLabelNode?
private var magicStick : SKEmitterNode?
override func didMove(to view: SKView) {
/*
// Get label node from scene and store it for use later
self.label = self.childNode(withName: "//helloLabel") as? SKLabelNode
if let label = self.label {
label.alpha = 0.0
label.run(SKAction.fadeIn(withDuration: 2.0))
}*/
// Create shape node to use during mouse interaction
let w = (self.size.width + self.size.height) * 0.05
self.magicStick = SKEmitterNode(fileNamed: "MyParticle.sks")
if let magicStick = self.magicStick {
//magicStick.run(SKAction.repeatForever(SKAction.rotate(byAngle: CGFloat(Double.pi), duration: 1)))
magicStick.particleTexture = SKTexture(imageNamed: "magicstick2.png")
magicStick.run(SKAction.sequence([SKAction.fadeOut(withDuration: 0.5), SKAction.removeFromParent()]))
}
}
func touchDown(atPoint pos : CGPoint) {
if let n = self.magicStick?.copy() as! SKEmitterNode? {
n.position = pos
self.addChild(n)
}
}
func touchMoved(toPoint pos : CGPoint) {
if let n = self.magicStick?.copy() as! SKEmitterNode? {
n.position = pos
self.addChild(n)
}
}
func touchUp(atPoint pos : CGPoint) {
if let n = self.magicStick?.copy() as! SKEmitterNode? {
n.position = pos
self.addChild(n)
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for t in touches { self.touchDown(atPoint: t.location(in: self)) }
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for t in touches { self.touchMoved(toPoint: t.location(in: self)) }
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for t in touches { self.touchUp(atPoint: t.location(in: self)) }
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
for t in touches { self.touchUp(atPoint: t.location(in: self)) }
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}