game: fix: reload view work
This commit is contained in:
parent
8895367786
commit
323b360aee
@ -12,9 +12,7 @@ export default class extends AbstractView
|
|||||||
constructor(params)
|
constructor(params)
|
||||||
{
|
{
|
||||||
super(params, "Game");
|
super(params, "Game");
|
||||||
this.game = new Game(client, params.id, this.on_goal, this.on_finish);
|
this.game_id = params.id;
|
||||||
this.keys_pressed = [];
|
|
||||||
this.my_player = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keyReleaseHandler(event)
|
keyReleaseHandler(event)
|
||||||
@ -76,7 +74,7 @@ export default class extends AbstractView
|
|||||||
clearInterval(loop_id);
|
clearInterval(loop_id);
|
||||||
this.my_player?.update_paddle(this.keys_pressed);
|
this.my_player?.update_paddle(this.keys_pressed);
|
||||||
this.render_game();
|
this.render_game();
|
||||||
this.game?.time.new_frame();
|
this.game?.time?.new_frame();
|
||||||
//clearInterval(loop_id);
|
//clearInterval(loop_id);
|
||||||
// 1 sec fps
|
// 1 sec fps
|
||||||
}, 1000 / 60);
|
}, 1000 / 60);
|
||||||
@ -170,8 +168,6 @@ export default class extends AbstractView
|
|||||||
|
|
||||||
data = [{x: 0, y: 0}, ...data];
|
data = [{x: 0, y: 0}, ...data];
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
data.push({x: Math.round((this.game.stop_timestamp - this.game.start_timestamp) / 1000),
|
data.push({x: Math.round((this.game.stop_timestamp - this.game.start_timestamp) / 1000),
|
||||||
y: data[data.length - 1].y});
|
y: data[data.length - 1].y});
|
||||||
|
|
||||||
@ -234,6 +230,10 @@ export default class extends AbstractView
|
|||||||
|
|
||||||
async postInit()
|
async postInit()
|
||||||
{
|
{
|
||||||
|
this.game = new Game(client, this.game_id, this.on_goal, this.on_finish);
|
||||||
|
this.keys_pressed = [];
|
||||||
|
this.my_player = undefined;
|
||||||
|
|
||||||
let error_code = await this.game.init();
|
let error_code = await this.game.init();
|
||||||
|
|
||||||
if (error_code)
|
if (error_code)
|
||||||
@ -249,6 +249,7 @@ export default class extends AbstractView
|
|||||||
this.game.leave();
|
this.game.leave();
|
||||||
this.game = undefined;
|
this.game = undefined;
|
||||||
}
|
}
|
||||||
|
this.game = undefined;
|
||||||
this.unregister_key();
|
this.unregister_key();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user