I have been working on implementing an object-oriented approach in my program. According to what I've learned, there should be an inheritance relationship between World and Sprite classes, with Sprite as the parent. However, when I try to call Sprite.call(this, imagePath), I encounter an issue where imagePath is undefined. This leads me to believe that other variables in the call might also be undefined. How can I properly access the parent variables in this scenario?
function Sprite(spriteX, spriteY, spriteW, spriteH, scale, positionX, positionY, direction)
{
this.imagePath = world_sprite;
this.spriteX = spriteX;
this.spriteY = spriteY;
this.spriteW = spriteW;
this.spriteH = spriteH;
this.scale = scale;
this.positionX = positionX;
this.positionY = positionY;
this.direction = direction;
this.speed = 5;
this.noGravity = false;
this.direction = 0;
//Physics stuff
this.velX = 0;
this.velY = 0;
this.friction = 0.98;
};
function World(posX, posY, direction, xOffset, yOffset)
{
Sprite.call(this, imagePath, positionX, positionY, direction);
this.spriteX = 0;
this.spriteY = 0;
this.spriteW = 400;
this.spriteH = 400;
this.scale = 0.4;
this.xOffset = xOffset;
this.yOffset = yOffset;
this.lives = 3;
};