Issue
I'm trying to implement inheritance 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 the 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
Solution
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);
Answered By - User456
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.