JavaNerd Posted March 5, 2018 Share Posted March 5, 2018 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 More sharing options...
PsichiX Posted March 5, 2018 Share Posted March 5, 2018 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 More sharing options...
JavaNerd Posted March 6, 2018 Author Share Posted March 6, 2018 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 More sharing options...
Recommended Posts