我正在尝试扩展pixi.js的sprite类并在我的子类构造函数中将其设置为position.x属性
var Ship = function(x, y, image, focused) {
PIXI.Sprite.fromImage.call(this, image);
this.x = x;
this.y = y;
this.image = image;
this.focused = typeof focused != 'undefined' ? focused : false;
this.position.x = window.width/2;
};
Ship.prototype = Object.create(PIXI.Sprite.fromImage.prototype);
Ship.prototype.constructor = Ship;
但是,我不断收到错误“未捕获的TypeError:无法设置未定义的属性'x'”
this.position.x = window.width/2;
我相信直到Object.create()调用之后,我才能访问父类的属性。那么这样做的正确方法是什么?
最佳答案
Ship.prototype = Object.create(PIXI.Sprite.prototype);
应该做的把戏!
关于javascript - 在构造函数中扩展pixi.js Sprite 来访问父级的属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28140597/