Jump to content

How to extend a sprite outside of create function


squeege
 Share

Recommended Posts

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));
};
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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