This repository was archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestroyState.swift
More file actions
55 lines (44 loc) · 1.74 KB
/
DestroyState.swift
File metadata and controls
55 lines (44 loc) · 1.74 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// DestroyState.swift
// Bomberman
//
// Created by Wolfgang Schreurs on 30/04/16.
//
//
import GameplayKit
import SpriteKit
class DestroyState: State {
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
return (stateClass is SpawnState.Type)
}
override func didEnter(from previousState: GKState?) {
super.didEnter(from: previousState)
if let entity = self.entity {
entity.delegate?.entityWillDestroy(entity)
}
}
override func updateForEntity(_ entity: Entity, configComponent: ConfigComponent, visualComponent: VisualComponent, didUpdate: @escaping () -> Void) {
var actions = [SKAction]()
visualComponent.spriteNode.removeAllActions()
if let destroySound = configComponent.destroySound {
let filePath = configComponent.configFilePath.stringByAppendingPathComponent(destroySound)
let play = playAction(forFileAtPath: filePath, spriteNode: visualComponent.spriteNode)
actions.append(play)
}
let destroyAnim = SKAction.animation(forEntity: entity,
configuration: configComponent.destroyAnimation,
state: self)
destroyAnim.forEach({ actions.append($0) })
// let fadeOut = SKAction.fadeOutWithDuration(0.5)
// actions.append(fadeOut)
let completion = {
didUpdate()
entity.delegate?.entityDidDestroy(entity)
}
if actions.count > 0 {
visualComponent.spriteNode.run(SKAction.sequence(actions), completion: completion)
} else {
completion()
}
}
}