Babsobar Posted March 23, 2018 Share Posted March 23, 2018 Hello, I'm trying to call a function in another file called createButtons.js; which contains this: function createButtons (){ //Create Back to menu Button var menuButton = this.add.sprite(width-width+120,height-height+60,'menuButtons','editorb0.png'); menuButton.setInteractive(); menuButton.on('pointerdown', function(pointer){ this.scene.start('MainMenu') },this) menuButton.setScrollFactor(0); } The function is loaded in my index.html; then I call the function in my main file in the create section simply with "createButtons();". I get the TypeError: "this.add is undefined" in the console. Any help is greatly appreciated, I'm sort of a noob in all this but i'm learning Link to comment Share on other sites More sharing options...
samme Posted March 23, 2018 Share Posted March 23, 2018 4 hours ago, Babsobar said: I call the function in my main file in the create section simply with "createButtons();" createButtons.call(this); Link to comment Share on other sites More sharing options...
Babsobar Posted March 23, 2018 Author Share Posted March 23, 2018 2 hours ago, samme said: createButtons.call(this); Works perfectly, thank you very much. This is new in phaser 3? I think I remember that in 2 you just called them the classic way Link to comment Share on other sites More sharing options...
Recommended Posts