Hi,
I want to use CreateFromObjects
to create Players, which are custom classes that extend the Phase.GameObjects.Sprite
object.
I thought I could achieve this using the the classType
property. But I get the following error:
TS2740: Type 'typeof Player' is missing the following properties from type 'GameObject': scene, displayList, type, state, and 42 more.
( I’m using typescript )
Here is example code:
import * as Phaser from 'phaser';
class Player extends Phaser.GameObjects.Sprite {
constructor(scene: Phaser.Scene, x: number, y: number) {
super(scene, x, y, "player_blue");
}
}
const sceneConfig: Phaser.Types.Scenes.SettingsConfig = {
active: false,
visible: false,
key: 'Game',
};
export class GameScene extends Phaser.Scene {
private player: Player;
constructor() {
super(sceneConfig);
}
public preload() {
this.load.image("tiles_board", "/assets/tilesets/board.png");
this.load.image("player_blue", "/assets/sprites/player_blue.png");
this.load.tilemapTiledJSON('map_test', '/assets/maps/test.json');
}
public create() {
const map = this.make.tilemap({ key: 'map_test' });
const tiles = map.addTilesetImage("tiles_board");
map.createLayer('main', tiles);
const players: Player[] = <Player[]>map.createFromObjects('players', {
name: 'player1',
classType: Player
});
this.player = players[0];
}
}
I feel like I’m missing something fundamental about how typescript inheritance works, but I can’t see what. Could anyone point out my mistake?
Thanks!