When you're invoking the GameObject
function here:
FlappyBird.prototype = new GameObject();
...you're not passing any arguments, so clearly the members, like actor
, that expect those arguments will have the value undefined
. So this.actor.position
will fail with a TypeError.
A better approach would be to do this:
FlappyBird.prototype = Object.create(GameObject.prototype);
...since the per-instance stuff shouldn't be needed on the FlappyBird.prototype
.
Code in the question was updated.
And this is obviously going to be a problem since you're going to have infinite recursion.
function FlappyBird(stage) {
// vv---Will infinitely recurse
FlappyBird.call(this, 50, 50, 50, 50, PIXI.Sprite.fromFrame("flappy01.png"), stage); //inherits from the game object
console.log(this instanceof GameObject);
console.log(this instanceof FlappyBird);
}
You probably meant to call GameObject
instead
function FlappyBird(stage) {
// vv---Applies the `GameObject` constructor to the `FlappyBird` object.
GameObject.call(this, 50, 50, 50, 50, PIXI.Sprite.fromFrame("flappy01.png"), stage); //inherits from the game object
console.log(this instanceof GameObject);
console.log(this instanceof FlappyBird);
}