the-world-engine
Version:
three.js based, unity like game engine for browser
61 lines (58 loc) • 2.16 kB
JavaScript
import { Component } from "../../hierarchy_object/Component";
import { Directable, Direction } from "../helper/Directable";
import { SpriteAtlasAnimator } from "../post_render/SpriteAtlasAnimator";
export class MovementAnimationController extends Component {
disallowMultipleComponent=true;
requiredComponents=[ Directable, SpriteAtlasAnimator ];
Ar=null;
kr=null;
qr=Direction.Down;
zr=false;
awake() {
this.Ar = this.gameObject.getComponent(Directable);
this.kr = this.gameObject.getComponent(SpriteAtlasAnimator);
}
update() {
const i = this.Ar.direction;
const t = this.Ar.isMoving;
if (t) {
if (i === Direction.Up) {
if (this.zr !== t || this.qr !== i) {
this.kr.playAnimation("up_walk");
}
} else if (i === Direction.Down) {
if (this.zr !== t || this.qr !== i) {
this.kr.playAnimation("down_walk");
}
} else if (i === Direction.Left) {
if (this.zr !== t || this.qr !== i) {
this.kr.playAnimation("left_walk");
}
} else if (i === Direction.Right) {
if (this.zr !== t || this.qr !== i) {
this.kr.playAnimation("right_walk");
}
}
} else {
if (i === Direction.Up) {
if (this.zr !== t || this.qr !== i) {
this.kr.playAnimation("up_idle");
}
} else if (i === Direction.Down) {
if (this.zr !== t || this.qr !== i) {
this.kr.playAnimation("down_idle");
}
} else if (i === Direction.Left) {
if (this.zr !== t || this.qr !== i) {
this.kr.playAnimation("left_idle");
}
} else if (i === Direction.Right) {
if (this.zr !== t || this.qr !== i) {
this.kr.playAnimation("right_idle");
}
}
}
this.zr = t;
this.qr = i;
}
}