Refactor Class
- Add MapManager permit to create map, camera and player. - Add CameraManager permit to move and update camera. - Add player Call extended of Phaser.GameObjects.Sprite. Permit to manager player data and moving in the map. - Add Animation class permit to manage the player animations.
This commit is contained in:
parent
833e7554f4
commit
5d463d097a
7 changed files with 366 additions and 186 deletions
60
front/src/Phaser/Player/Animation.ts
Normal file
60
front/src/Phaser/Player/Animation.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
interface AnimationData {
|
||||
key: string;
|
||||
frameRate: number;
|
||||
repeat: number;
|
||||
frameModel: string; //todo use an enum
|
||||
frameStart: number;
|
||||
frameEnd: number;
|
||||
}
|
||||
|
||||
export enum PlayerAnimationNames {
|
||||
WalkDown = 'down',
|
||||
WalkLeft = 'left',
|
||||
WalkUp = 'up',
|
||||
WalkRight = 'right',
|
||||
None = 'none',
|
||||
};
|
||||
|
||||
export const getPlayerAnimations = (PlayerValue : string): AnimationData[] => {
|
||||
return [{
|
||||
key: PlayerAnimationNames.WalkDown,
|
||||
frameModel: PlayerValue,
|
||||
frameStart: 0,
|
||||
frameEnd: 2,
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
}, {
|
||||
key: PlayerAnimationNames.WalkLeft,
|
||||
frameModel: PlayerValue,
|
||||
frameStart: 3,
|
||||
frameEnd: 5,
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
}, {
|
||||
key: PlayerAnimationNames.WalkRight,
|
||||
frameModel: PlayerValue,
|
||||
frameStart: 6,
|
||||
frameEnd: 8,
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
}, {
|
||||
key: PlayerAnimationNames.WalkUp,
|
||||
frameModel: PlayerValue,
|
||||
frameStart: 9,
|
||||
frameEnd: 11,
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
}];
|
||||
};
|
||||
|
||||
export const playAnimation = (Player : Phaser.GameObjects.Sprite, direction : string) => {
|
||||
if (!Player.anims.currentAnim || Player.anims.currentAnim.key !== direction) {
|
||||
if (direction !== PlayerAnimationNames.None) {
|
||||
Player.anims.play(direction);
|
||||
} else if (Player.anims.isPlaying) {
|
||||
Player.anims.stop();
|
||||
}
|
||||
} else if (direction === PlayerAnimationNames.None && Player.anims.currentAnim) {
|
||||
Player.anims.currentAnim.destroy();
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue