MCPcopy Create free account
hub / github.com/melonjs/melonJS / _switchState

Function _switchState

packages/melonjs/src/state/state.ts:175–210  ·  view source on GitHub ↗

* start the SO main loop * @ignore

(stateId: number)

Source from the content-addressed store, hash-verified

173 * @ignore
174 */
175function _switchState(stateId: number): void {
176 // clear previous interval if any
177 _stopRunLoop();
178
179 // call the stage destroy method
180 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
181 if (_stages[_state]) {
182 _stages[_state].stage.destroy(_app);
183 }
184
185 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
186 if (_stages[stateId]) {
187 // set the global variable
188 _state = stateId;
189
190 // call the reset function with the app reference and any extra args
191 if (_extraArgs) {
192 _stages[_state].stage.reset(_app, ..._extraArgs);
193 } else {
194 _stages[_state].stage.reset(_app);
195 }
196
197 // and start the main loop of the
198 // new requested state
199 _startRunLoop();
200
201 // publish the pause event
202 emit(STATE_CHANGE);
203
204 // execute callback if defined
205 if (_onSwitchComplete) {
206 _onSwitchComplete();
207 _onSwitchComplete = null;
208 }
209 }
210}
211
212// the active application instance
213let _app: Application;

Callers 1

changeFunction · 0.85

Calls 5

emitFunction · 0.90
_stopRunLoopFunction · 0.85
_startRunLoopFunction · 0.85
destroyMethod · 0.65
resetMethod · 0.45

Tested by

no test coverage detected