My situation is that I am working on a Canvas game using Box2DWeb, so I have a class called Sprite that draws an image to the Canvas, I now want to create a PhysicsSprite class that inherits methods and properties from Sprite.
My Sprite class (Sprite.js):
Sprite = function (position, dimension, image) {
this.Position = position;
this.Dimension = dimension;
if (image)
this.Image = image;
...
this.Draw = function (g) {
...
}
...
};
And I am setting the prototype in PhysicsSprite (PhysicsSprite.js) like so:
PhysicsSprite = function(position, dimension, world) {
this.prototype = new Sprite(position, dimension, undefined);
//alert(this.prototype.Position.X)
var body = CreateBody();
this.GetBody = function () { return body; }
this.Draw = function (g) {
...
}
function CreateBody () {
...
}
};
Note the alert(this.prototype.Position.X), which does alert me of the position, but if I change the code to this.Position.X, I get an error, and similarly, if I have an instance of PhysicsSprite, I have to explicitly call the prototype.
This lead me to think that I haven't set the Object's prototype, merely created a property called prototype
, and set that to a new Sprite.
If someone could help me, and explain what I am doing wrong, that would be much appreciated. I am dyslexic, so I always misspell variables, which is frustrating, so that was the first thing I looked for, but everything looks fine to me.