Files
CINC/objects/Unit.js
T

16 lines
452 B
JavaScript

export default class Unit extends Phaser.Physics.Arcade.Sprite {
constructor(scene, x, y, texture) {
super(scene, x, y, texture);
scene.add.existing(this);
scene.physics.add.existing(this);
this.setCollideWorldBounds(true);
}
moveTo(targetX, targetY) {
this.scene.physics.moveToObject(this, {x: targetX, y: targetY}, 200);
}
moveRelative(dirX, dirY, speed = 100) {
this.setVelocity(dirX * speed, dirY * speed);
}
}