Skip to content

Commit

Permalink
Fix: extra sprite was created for local player and fixed at 0,0
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-bell committed Apr 8, 2021
1 parent 818de3d commit 2400d69
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions frontend/src/components/world/WorldMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CoveyGameScene extends Phaser.Scene {
sprite: Phaser.Types.Physics.Arcade.SpriteWithDynamicBody, label: Phaser.GameObjects.Text
};

private id?: string;
private myPlayerID: string;

private players: Player[] = [];

Expand All @@ -33,10 +33,11 @@ class CoveyGameScene extends Phaser.Scene {

private emitMovement: (loc: UserLocation) => void;

constructor(video: Video, emitMovement: (loc: UserLocation) => void) {
constructor(video: Video, emitMovement: (loc: UserLocation) => void, myPlayerID : string) {
super('PlayGame');
this.video = video;
this.emitMovement = emitMovement;
this.myPlayerID = myPlayerID;
}

preload() {
Expand Down Expand Up @@ -89,7 +90,7 @@ class CoveyGameScene extends Phaser.Scene {
myPlayer = new Player(player.id, player.userName, location);
this.players.push(myPlayer);
}
if (this.id !== myPlayer.id && this.physics && player.location) {
if (this.myPlayerID !== myPlayer.id && this.physics && player.location) {
let { sprite } = myPlayer;
if (!sprite) {
sprite = this.physics.add
Expand Down Expand Up @@ -433,7 +434,7 @@ class CoveyGameScene extends Phaser.Scene {
export default function WorldMap(): JSX.Element {
const video = Video.instance();
const {
emitMovement, players,
emitMovement, players, myPlayerID,
} = useCoveyAppState();
const [gameScene, setGameScene] = useState<CoveyGameScene>();
useEffect(() => {
Expand All @@ -452,7 +453,7 @@ export default function WorldMap(): JSX.Element {

const game = new Phaser.Game(config);
if (video) {
const newGameScene = new CoveyGameScene(video, emitMovement);
const newGameScene = new CoveyGameScene(video, emitMovement, myPlayerID);
setGameScene(newGameScene);
game.scene.add('coveyBoard', newGameScene, true);
video.pauseGame = () => {
Expand All @@ -465,7 +466,7 @@ export default function WorldMap(): JSX.Element {
return () => {
game.destroy(true);
};
}, [video, emitMovement]);
}, [video, emitMovement, myPlayerID]);

const deepPlayers = JSON.stringify(players);
useEffect(() => {
Expand Down

0 comments on commit 2400d69

Please sign in to comment.