The title of the question may not be the best but here's the code I've written so far:
var menuState = {
//state variables
menuBttn: {
x: _canvas.width/2,
y:_canvas.height/2,
img: imageArray[2],
over: false,
click: function() {
changeState(2);
}
},
preload: function () {
},
update: function(){
surface.clearRect(0, 0, _canvas.width, _canvas.height);
for (var i = 0; i < menuAssets; i++){
surface.drawImage(//draw menuBttn);
}
},
exit: function(){
},
};
What I want to do is essentially create a variable called menuButtn (which is an object) that only exists within menuState.
I thought I could do this by doing:
var menuState = {
//state variables
this.menuBttn = {
x: _canvas.width/2,
y:_canvas.height/2,
img: imageArray[2],
over: false,
click: function(){
changeState(2);
}
},
}
This is the way it works in Phaser.io (a library for making games), but I'm trying to make my own game engine.
How do I go about it?