Skip to content

Commit 9fc92d0

Browse files
committed
Update Xcode templates for scenes
- Use updated component names. - Trim unnecessary code and whitespace from the Multi-State Scene template. - Fix outdated code, placeholders in the Multi-State Scene template. - Improve comments in the Multi-State Scene template.
1 parent 1a6c5ef commit 9fc92d0

File tree

2 files changed

+29
-58
lines changed

2 files changed

+29
-58
lines changed

Templates/Xcode/OctopusKit Multi-State Scene.xctemplate/___FILEBASENAME___.swift

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import GameplayKit
1010
final class PlayableState: OctopusGameState {
1111

1212
init() {
13-
super.init(associatedSceneClass: GameScene.self)
13+
super.init(associatedSceneClass: ___FILEBASENAMEASIDENTIFIER___.self)
1414
}
1515

1616
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
@@ -25,7 +25,7 @@ final class PlayableState: OctopusGameState {
2525
final class PausedState: OctopusGameState {
2626

2727
init() {
28-
super.init(associatedSceneClass: GameScene.self)
28+
super.init(associatedSceneClass: ___FILEBASENAMEASIDENTIFIER___.self)
2929
}
3030

3131
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
@@ -37,29 +37,13 @@ final class ___FILEBASENAMEASIDENTIFIER___: OctopusScene {
3737

3838
// MARK: - Life Cycle
3939

40-
override func willMove(to view: SKView) {
41-
super.willMove(to: view)
42-
// Set scaling and any other properties that need to be set before presenting in the view.
43-
// self.scaleAndCropToFitLandscape(in: view) // Fill landscape orientation at the cost of cutting out some edges.
44-
// self.halveSizeAndFit(in: view) // For a pixelated effect.
45-
}
46-
47-
/*
48-
override func didMove(to view: SKView) {
49-
super.didMove(to: view)
50-
// view.setAllDebugStatsVisibility(to: true)
51-
// view.showsPhysics = false
52-
}
53-
*/
54-
5540
override func prepareContents() {
5641
super.prepareContents()
5742
createComponentSystems()
5843
createEntities()
5944
}
6045

6146
fileprivate func createComponentSystems() {
62-
6347
componentSystems.createSystems(forClasses: [ // Customize
6448

6549
// 1: Time and state.
@@ -73,34 +57,37 @@ final class ___FILEBASENAMEASIDENTIFIER___: OctopusScene {
7357
NodeTouchComponent.self,
7458
NodeTouchClosureComponent.self,
7559
MotionManagerComponent.self,
76-
TouchControlledPositioningComponent.self,
7760

7861
// 3: Movement and physics.
7962

63+
TouchControlledPositioningComponent.self,
8064
OctopusAgent2D.self,
8165
PhysicsComponent.self, // The physics component should come in after other components have modified node properties, so it can clamp the velocity etc. if such limits have been specified.
8266

8367
// 4: Custom code and anything else that depends on the final placement of nodes per frame.
8468

85-
PhysicsContactEventComponent.self,
86-
RepeatedClosureComponent.self,
69+
PhysicsEventComponent.self,
70+
RepeatingClosureComponent.self,
8771
DelayedClosureComponent.self,
8872
CameraComponent.self
8973
])
9074
}
9175

9276
fileprivate func createEntities() {
77+
// Customize: This is where you build your scene.
78+
//
79+
// You may also perform scene construction and deconstruction in `gameControllerDidEnterState(_:from:)` and `gameControllerWillExitState(_:to:)`
9380
}
9481

9582
// MARK: - Frame Update
9683

9784
override func update(_ currentTime: TimeInterval) {
9885
super.update(currentTime)
99-
guard !isPaused, !isPausedBySystem, !isPausedByPlayer, !isPausedByModalInterface else { return }
86+
guard !isPaused, !isPausedBySystem, !isPausedByPlayer, !isPausedBySubscene else { return }
10087

10188
// Update game state, entities and components.
10289

103-
OctopusEngine.shared?.gameController.update(deltaTime: updateTimeDelta)
90+
OctopusKit.shared?.gameController.update(deltaTime: updateTimeDelta)
10491
updateSystems(in: componentSystems, deltaTime: updateTimeDelta)
10592
}
10693

@@ -110,83 +97,67 @@ final class ___FILEBASENAMEASIDENTIFIER___: OctopusScene {
11097
override func gameControllerDidEnterState(_ state: GKState, from previousState: GKState?) {
11198
super.gameControllerDidEnterState(state, from: previousState)
11299

113-
// Common to every state, before state-specific
114-
115-
// ...
100+
// If this scene needs to perform tasks which are common to every state, you may put that code outside the switch statement.
116101

117-
// State-specific
118-
119-
switch type(of: state) { // Can also use tuples: `(type(of: previousState), type(of: state))`
102+
switch type(of: state) { // Tuples may be used here: `(type(of: previousState), type(of: state))`
120103

121-
case is PlayableState.Type: // Entering PlayableState
104+
case is PlayableState.Type: // Entering `PlayableState`
122105
break
123106

124-
case is PausedState.Type: // Entering PausedState
107+
case is PausedState.Type: // Entering `PausedState`
125108
physicsWorld.speed = 0
126109

127110
default:
128111
break
129112
}
130-
131-
// Common to every state, after state-specific
132-
133-
// ...
134113
}
135114

136115
/// Useful in games that use a single scene for multiple games states (e.g. removing overlays that were displaying during a paused state, menus, etc.)
137116
override func gameControllerWillExitState(_ exitingState: GKState, to nextState: GKState) {
138117
super.gameControllerWillExitState(exitingState, to: nextState)
139118

140-
// Common to every state, before state-specific
141-
142-
// ...
119+
// If this scene needs to perform tasks which are common to every state, you may put that code outside the switch statement.
143120

144-
// State-specific
145-
146-
switch type(of: exitingState) { // Can also use tuples: `(type(of: exitingState), type(of: nextState))`
121+
switch type(of: exitingState) { // Tuples may be used here: `(type(of: exitingState), type(of: nextState))`
147122

148-
case is PlayableState.Type: // Exiting PlayableState
123+
case is PlayableState.Type: // Exiting `PlayableState`
149124
break
150125

151-
case is PausedState.Type: // Exiting PausedState
126+
case is PausedState.Type: // Exiting `PausedState`
152127
physicsWorld.speed = 1
153128

154129
default:
155130
break
156131
}
157-
158-
// Common to every state, after state-specific
159-
160-
// ...
161132
}
162133

163-
override func pausedBySystem() {
164-
if
165-
let currentState = OctopusEngine.shared?.gameController.currentState,
134+
// MARK: - Pausing/Unpausing
135+
136+
override func didPauseBySystem() {
137+
if let currentState = OctopusKit.shared?.gameController.currentState,
166138
type(of: currentState) is PlayableState.Type
167139
{
168140
self.octopusSceneDelegate?.octopusScene(self, didRequestGameStateClass: PausedState.self)
169141
}
170142
}
171143

172-
override func unpausedBySystem() {
173-
// Remain in the paused state so the player has to manually unpause when they are ready.
144+
override func didUnpauseBySystem() {
145+
// If we were in the paused game state, remain in that state so the player has to manually unpause when they are ready.
174146

175-
if
176-
let currentState = OctopusEngine.shared?.gameController.currentState,
147+
if let currentState = OctopusKit.shared?.gameController.currentState,
177148
type(of: currentState) is PausedState.Type
178149
{
179150
// Since we are still in the paused state, keep the action paused, preventing `super.applicationDidBecomeActive()` from resuming it.
180151
physicsWorld.speed = 0
181152
}
182153
}
183154

184-
override func pausedByPlayer() {
155+
override func didPauseByPlayer() {
185156
// This transition should be subject to the validation logic in the relevant `OctopusGameState` classes.
186157
self.octopusSceneDelegate?.octopusScene(self, didRequestGameStateClass: PausedState.self)
187158
}
188159

189-
override func unpausedByPlayer() {
160+
override func didUnpauseByPlayer() {
190161
// This transition should be subject to the validation logic in the relevant `OctopusGameState` classes.
191162
self.octopusSceneDelegate?.octopusScene(self, didRequestGameStateClass: PlayableState.self)
192163
}

Templates/Xcode/OctopusKit Scene.xctemplate/___FILEBASENAME___.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ final class ___FILEBASENAMEASIDENTIFIER___: OctopusScene {
3636

3737
// 4: Custom code and anything else that depends on the final placement of nodes per frame.
3838

39-
PhysicsContactEventComponent.self,
40-
RepeatedClosureComponent.self,
39+
PhysicsEventComponent.self,
40+
RepeatingClosureComponent.self,
4141
DelayedClosureComponent.self,
4242
CameraComponent.self
4343
])

0 commit comments

Comments
 (0)