From: kharhamel Date: Sun, 12 Apr 2020 16:28:05 +0000 (+0200) Subject: fixed the player animations X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=97a55ab66cd61a3b875fa4ef24bdb98d8d9fd677;p=libreadventure.git fixed the player animations --- diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index dac1f2f..648e657 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -6,7 +6,7 @@ import {NonPlayer} from "../NonPlayer/NonPlayer"; export enum Textures { Rock = 'rock', - Player = 'player', + Player = 'playerModel', Map = 'map', Tiles = 'tiles' } @@ -39,7 +39,11 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ 'resources/characters/pipoya/Male 01-1.png', { frameWidth: 32, frameHeight: 32 } ); + } + //hook create scene + create(): void { + //anims cannot be in preload because it needs to wait to the sprit to be loaded getPlayerAnimations().forEach(d => { this.anims.create({ key: d.key, @@ -48,10 +52,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ //repeat: d.repeat }); }); - } - - //hook create scene - create(): void { + this.userInputManager = new UserInputManager(this); //create entities @@ -68,8 +69,8 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ //create map let currentMap = this.add.tilemap(Textures.Map); let terrain = currentMap.addTilesetImage(Textures.Tiles, "tiles"); - let bottomLayer = currentMap.createStaticLayer("Calque 1", [terrain], 0, 0).setDepth(-1); - let topLayer = currentMap.createStaticLayer("Calque 2", [terrain], 0, 0); + let bottomLayer = currentMap.createStaticLayer("Calque 1", [terrain], 0, 0).setDepth(-2); + let topLayer = currentMap.createStaticLayer("Calque 2", [terrain], 0, 0).setDepth(-1); this.physics.world.setBounds(0,0, currentMap.widthInPixels, currentMap.heightInPixels); this.physics.add.collider(this.player, topLayer); @@ -105,6 +106,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ this.player.move(eventList); this.otherPlayers.getChildren().forEach((otherPlayer: NonPlayer) => { + //this.physics.accelerateToObject(otherPlayer, this.player); //this line make the models chase the player otherPlayer.setVelocity(20, 5); }) } diff --git a/front/src/Phaser/NonPlayer/NonPlayer.ts b/front/src/Phaser/NonPlayer/NonPlayer.ts index d9b2200..46fa645 100644 --- a/front/src/Phaser/NonPlayer/NonPlayer.ts +++ b/front/src/Phaser/NonPlayer/NonPlayer.ts @@ -4,7 +4,7 @@ import {Textures} from "../Game/GameScene"; export class NonPlayer extends PlayableCaracter { constructor(scene: Phaser.Scene, x: number, y: number) { - super(scene, x, y, Textures.Player, 26); + super(scene, x, y, Textures.Player, 1); this.setSize(32, 32); //edit the hitbox to better match the caracter model } } \ No newline at end of file diff --git a/front/src/Phaser/Player/Player.ts b/front/src/Phaser/Player/Player.ts index e4395b3..ff2278f 100644 --- a/front/src/Phaser/Player/Player.ts +++ b/front/src/Phaser/Player/Player.ts @@ -7,7 +7,7 @@ import {PlayableCaracter} from "../Entity/PlayableCaracter"; export class Player extends PlayableCaracter{ constructor(scene: Phaser.Scene, x: number, y: number) { - super(scene, x, y, Textures.Player, 26); + super(scene, x, y, Textures.Player, 1); this.setImmovable(false); //the current player model should be push away by other players to prevent conflict this.setSize(32, 32); //edit the hitbox to better match the caracter model } @@ -19,27 +19,28 @@ export class Player extends PlayableCaracter{ if(activeEvents.get(UserInputEvent.MoveUp)){ this.setVelocity(0, -speed) - playAnimation(this, PlayerAnimationNames.WalkUp); } else if(activeEvents.get(UserInputEvent.MoveLeft)){ this.setVelocity(-speed, 0) } else if(activeEvents.get(UserInputEvent.MoveDown)){ - playAnimation(this, PlayerAnimationNames.WalkDown); this.setVelocity(0, speed) } else if(activeEvents.get(UserInputEvent.MoveRight)){ this.setVelocity(speed, 0) } else { this.setVelocity(0, 0) - playAnimation(this, PlayerAnimationNames.None); + } + + if (this.body.velocity.x > 0) { //moving right + this.play("right", true); + } else if (this.body.velocity.x < 0) { //moving left + this.anims.playReverse("left", true); + } else if (this.body.velocity.y < 0) { //moving up + this.play("up", true); + } else if (this.body.velocity.y > 0) { //moving down + this.play("down", true); } } stop() { this.setVelocity(0, 0) } - - /*private sharePosition(direction : string){ - if(ConnexionInstance) { - ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y, direction); - } - }*/ } \ No newline at end of file