Jump to content

Spawn an image when clicking a button


JavaNerd
 Share

Recommended Posts

I keep getting this.add is undefined.

		// Building button
		ui1.on('pointerdown', function ()
		{
			var window = this.add.image(0, 0, 'window').setOrigin(0);
			window.setScrollFactor(0);
			window.setDepth(1002);
			window.x = 20;
			window.y = 20;
		});

I'm trying to spawn an image into the game when the user clicks on the button.

Link to comment
Share on other sites

check docs about .on function - if it accepts third parameter as context, pass your proper context instance - if not, bind this anon function with context:

ui1.on('name', function(){}, someParent);

or:

ui1.on('name', (function(){}).bind(someParent));

Link to comment
Share on other sites

14 hours ago, PsichiX said:

check docs about .on function - if it accepts third parameter as context, pass your proper context instance - if not, bind this anon function with context:

ui1.on('name', function(){}, someParent);

or:

ui1.on('name', (function(){}).bind(someParent));

Once again, thank you!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...