javascript - Trying to refactor an animation into a class object, how to construct its interrelating parts -
i'm trying refactor animation code class object can instantiated.
the original code file functions , variables, , called variables functions, turning out little bit of problem since 1 of things code had constructor populate array.
i'm little confused @ how put aspect new class constructor function, since mini class particle has method of own called .use has ctx variables inside that. how point ctx information thats contained in rest of function since in scope area?
i tried adding .use method prototype drawslinky.prototype.particle.use
, when gets point should call function, says isn't function, imagine that didn't work.
here's code right now, error following :
drawslinky.prototype.particle = function(x, y, color, area, velocity, rad){ this.x = x; this.y = y; this.vx = math.cos(rad) * velocity; this.vy = math.sin(rad) * velocity; this.color = color; this.area = area; this.use = function(){ this.x += this.vx *= .99; this.y += this.vy *= .99; this.ctx.fillstyle = ctx.shadowcolor = this.color; this.ctx.shadowblur = this.area; this.ctx.beginpath(); this.ctx.arc(this.x, this.y, this.area/2, 0, math.pi*2); this.ctx.fill(); } };
this giving me error ctx property not defined. how work around , access ctx information in rest of object outside of .particle mini constructor?
this dealing super
in other languages. access super
data, use:
this.constructor
Comments
Post a Comment