I'm trying to implement inheritence in a game i'm making with typescript (pixi.js) but I'm getting stuck on this error. I have a class, Dog, with the following code:
export class Dog extends Enemy {
//private game: Game;
//private speed: number = 0;
constructor(texture: PIXI.Texture, game: Game) {
super(texture);
this.game = game;
}
I also have a class enemy, which the class dog extends to, with the following code:
export class Enemy extends PIXI.Sprite {
public game: Game;
public speed: number = 0;
constructor(texture: PIXI.Texture, game: Game) {
super(texture);
this.game = game;
}
But in my dog.ts file I get the following error under the super(texture); part of my code: Expected 2 arguments, but got 1.ts(2554) enemy.ts(8, 38): An argument for 'game' was not provided.
I have no idea what this means as I would expect I have given an argument for game in enemy.ts and I also extend to Pixi.sprite.
Edit: If i change the super in enemy.ts to super(texture, game) I get the following error: if I do this I get the following error: Expected 0-1 arguments, but got 2.ts(2554)
I can only put on argument in the super function so I'm afraid this won't fix the problem
Edit 2: Nvm I changed the wrong file
CodePudding user response:
Because you did not provide game
(which is a required argument) in super
.
In the Dog
class add game
parameter to the super
function:
super(texture, game);
CodePudding user response:
Well, the constructor of Enemy
expects two arguments in input: texture: PIXI.Texture, game: Game
but you are giving only the first one.
So, in your dog.ts
from
super(texture)
Modify to
super(texture, game)
The same error may appear in Enemy class if the Pixi.Sprite
expects the same two arguments.