squeege Posted January 12, 2019 Share Posted January 12, 2019 In my create function i create a game object food food = this.physics.add.sprite(200,400, 'food', 'orb1.png') food.setBounce(0.5); food.setCollideWorldBounds(true); I want to call a function on click (button) that will create another instance of this object. ive tried variances of everything ive found on forums without any luck. Example below. I have the click function firing but i cant seem to get the sprite to add to the scene when i click the button. I usually get an error like add of property undefined or that the object doesnt support that function. Any help on how to add a sprite outside of the create function would be appreciated. ie. function feedShrooms() { var food = this.add.sprite(new food(this,100,450,'food',0)); }; Quote Link to comment Share on other sites More sharing options...
mattstyles Posted January 14, 2019 Share Posted January 14, 2019 Hey @squeege, welcome to the forums. This answer might help as it sounds like you have the same scoping issue. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.