I’m digging OOP for the first time but I’ve got a little problem:
var panel = {
img : imgs[24],
prop : this.img.height / this.img.width,
h : this.img.height - (scale),
w : h/prop,
x : center.x - (w / 2),
y : center.y - (h / 2)
}
panel.draw = function(){
g.ctx.drawImage(this.img,
0, 0,
this.img.width, this.img.height,
this.x, this.y,
this.w, this.h)
}
But it looks like declaring this.img.height results in typeError. Can someone explain why?
Also, how can I declare the method inside the object declaration? Nothing special about it: I just don’t want my code to look too messy.
Is your object always static to the name panel? Then
Is it not static but you don’t want instances of it? Then make an initialisation function to get the correct
thisDo you want to have multiple instances of the object? Then make a constructor
and use with
var panel = new Panel( imgs[24] );