Hi, i got a class that updates and renders a button, wich i created.
My Button class looks like this:
and the basic class:Code:var Button = function(x,y,width,height,text){ this.rect = new Rectangle(x,y,width,height); this.text = text; this.hover = true; this.pressed = false; this.update = function(input){ this.hover = this.rect.Contains(input.x, input.y); if(this.hover && input.m_left && !this.pressed){ this.pressed = true; this.clicked(); } if(!input.m_left){ this.pressed = false; } }; this.render = function(ctx){ this.hover? this.rect.Draw(ctx, "blue"):this.rect.Draw(ctx, "red"); }; this.clicked = function(){}; };
The problem is, that Basic.x (i also tried this.x) is undefined, because the clicked funtion is executed in the button class.Code:var Basic = function(){ this.x = 100; this.b1 = new Button(0,0,200,50,"lol"); this.b1.clicked = function(){ this.rect.x += Basic.x; alert(this.x); }; this.update = function(input){ this.b1.update(input); }; this.render = function(ctx){ this.b1.render(ctx); }; };
How can i access elements from the Basic class, without giving them as argument to the Button class?
Thx![]()


Reply With Quote
Bookmarks