-
Notifications
You must be signed in to change notification settings - Fork 12
Classes
hazzard993 edited this page Jul 11, 2019
·
1 revision
TypeScriptToLua allows classes to be used!
class Player {}
const p = new Player();
Classes can contain methods and properties.
class Player {
private body: Body;
constructor() {
this.body = love.physics.newBody(...);
}
spawn() {}
}
They can extend each other.
class PlayerExtended extends Player {}
They can use interfaces to ensure certain members exist in the class.
class Player implements Entity { ... }
And they are also identifiable with instanceof
.
function spawnEntity(entity: Entity): void {
if (entity instanceof Player) {
// TS knows entity is a Player!
entity.spawn();
}
}