i assume it will be the scene in this case. i think they have phD’s in javascript this (and a bit o’ that) but once you get to it - its usually the last reference or passed object , if you were to onclick or mouseover a button and from there pass (this) to function then inside the function you can address all the properties (if thats what its called im not a pro) the object has
//game.js goes in separate file as do some global (im not into 'good practice' since im the only one reading and modding it so ...)
class SceneTOP extends Phaser.Scene {
constructor(){
super("commonmenu");
}
preload(){
this.canvas = this.sys.game.canvas; //here this refers to the scene
$('#scenevar1').val(0);
}
create(){
var thismenu = {
fontsize: '16px',
fontFamily: 'tahoma',
color: '#ffffff',
padding: 10,
backgroundColor: 'rgba(0,0,128,0.9)'
};
// this.tyrdate = this.add.text(0,0,window.tyrdate);
this.tyrdate = this.add.dom(0,0,'tyrdate',null,window.tyrdate).setOrigin(0,0); // it says 'optional' but i probably missing something @'tyrdate'
this.tyrdate.setClassName('tyrdate');
// this.loading = this.add.text(200,100,"this.loading txt can alter, mind"); // not needed anymore i guess
this.infotext = this.add.text(20,600, "mouse over ,touch, tag or click stuff", infopanelstyle); //<-- here this refers to the scene "add text to scene"
this.menuBTN1 = this.add.sprite(wu,20,'btn_account').setOrigin(0,0).setFrame(0).setInteractive({ pixelPerfect: true }).setDisplaySize(wu*20,wu*10)
/*
//stufff
*/
this.menu_oo = this.add.sprite(0,0,'btn_menu_outline_over').setOrigin(0,0).setVisible(0).setDisplaySize(wu*20,wu*10); //<-- just doodles since i have three frames per btn already , wu and wh are global referring to "window unit, relative to window size etc. etc .. in general someone like samme knows a lot more about where the mustard comes from tho ... i just couldnt resist)
this.menu_od = this.add.sprite(0,0,'btn_menu_outline_down').setOrigin(0,0).setVisible(0).setDisplaySize(wu*20,wu*10);
this.menuBTN1.infotext = "account info / secure settings";
/*
//...morestuff
*/
this.menuBTN1.on('pointerover', this.mouseoverbutton); <--- pass the button to function attached to scene
this.menuBTN1.on('pointerout', this.mouseoutbutton);
/*
//...evenmorestuff
*/
this.menuBTN1.on('pointerdown', function(event){
this.menuBTN1.setFrame(2);
this.menu_oo.setVisible(0);
this.menu_od.x = this.menuBTN1.x;
this.menu_od.y = this.menuBTN1.y;
this.menu_od.setVisible(1);
if(this.registry.values.currentscene == "loginGame"){
//there was steemit stuff here
}
this.scene.stop(this.registry.values.currentscene); <------- calling scene from button
this.time.delayedCall(40,function(){
$("#scenevar1" ).val(4);
$( "#fieldformdiv" ).html( "<img src=/media/UI/loading.gif >" );
this.scene.start("fasterthanclearing"); <-if this were the button it would probably need this.scene.scene.start(...
},[],this)
}, this); <-- passing the scene
/*
//hellamorestuff
*/
}
update(){
/*
//and then some stuff
*/
}
mouseoverbutton(){
this.setFrame(1); <------------------ this refers to the button
this.scene.menu_oo.x = this.x;
this.scene.menu_oo.y = this.y;
this.scene.menu_oo.setVisible(1);
//which was textobject before
// this.scaleX = 1.1;
// this.setStyle({color: '#00ff00', backgroundColor: 'rgba(0,0,128,0.5)'});
// this.setPadding({ y: 10, left: 10, right : 5});
this.scene.oldskoolfunkystack = this.scene.infotext.text;
this.scene.infotext.visible = true;
this.scene.infotext.text = this.infotext;
}
mouseoutbutton(){
//outstuff
}
}
its possible that this makes scholars cry but i just go with what works … if any pro-dev wants to add or correct something thats not about formatting or team-practice i am always willing to learn
wow … its so hard not to answer sometimes …