Fixing selection on keyboard after selection using mouse
authorDavid Négrier <d.negrier@thecodingmachine.com>
Tue, 26 May 2020 15:02:04 +0000 (17:02 +0200)
committerDavid Négrier <d.negrier@thecodingmachine.com>
Tue, 26 May 2020 15:02:04 +0000 (17:02 +0200)
front/src/Phaser/Login/SelectCharacterScene.ts

index 56dcb8a5397c936b42999b6a7231fadb11280a9a..138621daeea71333e355baa403f88eea2ab0d068 100644 (file)
@@ -156,8 +156,10 @@ export class SelectCharacterScene extends Phaser.Scene {
         for (let i = 0; i <PLAYER_RESOURCES.length; i++) {
             let playerResource = PLAYER_RESOURCES[i];
 
+            let col = i % this.nbCharactersPerRow;
+            let row = Math.floor(i / this.nbCharactersPerRow);
 
-            let [x, y] = this.getCharacterPosition(i % this.nbCharactersPerRow, Math.floor(i / this.nbCharactersPerRow));
+            let [x, y] = this.getCharacterPosition(col, row);
             let player = this.physics.add.sprite(x, y, playerResource.name, playerResource.name);
             player.setBounce(0.2);
             player.setCollideWorldBounds(true);
@@ -173,6 +175,8 @@ export class SelectCharacterScene extends Phaser.Scene {
                 this.selectedRectangle.setX(player.x);
                 player.play(playerResource.name);
                 this.selectedPlayer = player;
+                this.selectedRectangleXPos = col;
+                this.selectedRectangleYPos = row;
             });
             this.players.push(player);
         }