Merge pull request #177 from thecodingmachine/fixsuspend
Fixing suspend/resume
This commit is contained in:
commit
ac2e45c60e
@ -232,6 +232,8 @@ export class Connection implements ConnectionInterface {
|
||||
}
|
||||
|
||||
joinARoom(roomId: string, startX: number, startY: number, direction: string, moving: boolean): void {
|
||||
let point = new Point(startX, startY, direction, moving);
|
||||
this.lastPositionShared = point;
|
||||
this.getSocket().emit(EventMessage.JOIN_ROOM, { roomId, position: {x: startX, y: startY, direction, moving }}, (userPositions: MessageUserPositionInterface[]) => {
|
||||
this.GameManager.initUsersPosition(userPositions);
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ export interface MapObject {
|
||||
export class GameManager {
|
||||
//status: number;
|
||||
private ConnectionInstance: Connection;
|
||||
private currentGameScene: GameScene|null;
|
||||
private currentGameScene: GameScene|null = null;
|
||||
private playerName: string;
|
||||
SimplePeer : SimplePeer;
|
||||
private characterUserSelected: string;
|
||||
@ -168,7 +168,7 @@ export class GameManager {
|
||||
private oldMapUrlFile : string;
|
||||
private oldInstance : string;
|
||||
private scenePlugin: ScenePlugin;
|
||||
private reconnectScene: Scene;
|
||||
private reconnectScene: Scene|null = null;
|
||||
switchToDisconnectedScene(): void {
|
||||
if (this.currentGameScene === null) {
|
||||
return;
|
||||
@ -186,8 +186,15 @@ export class GameManager {
|
||||
}
|
||||
|
||||
reconnectToGameScene(lastPositionShared: PointInterface) {
|
||||
if (this.reconnectScene === null && this.currentGameScene) {
|
||||
// In case we are asked to reconnect even if switchToDisconnectedScene was not triggered (can happen when a laptop goes to sleep)
|
||||
this.switchToDisconnectedScene();
|
||||
// Wait a bit for scene to load. Otherwise, starting ReconnectingSceneName and then starting GameScene one after the other fails for some reason.
|
||||
setTimeout(() => this.reconnectToGameScene(lastPositionShared), 500);
|
||||
return;
|
||||
}
|
||||
const game : Phaser.Scene = GameScene.createFromUrl(this.oldMapUrlFile, this.oldInstance);
|
||||
this.reconnectScene.scene.add(this.oldSceneKey, game, true, { initPosition: lastPositionShared });
|
||||
this.reconnectScene?.scene.add(this.oldSceneKey, game, true, { initPosition: lastPositionShared });
|
||||
}
|
||||
|
||||
private getCurrentGameScene(): GameScene {
|
||||
|
Loading…
Reference in New Issue
Block a user