Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Method to clone a sprite?


iamhaas
 Share

Recommended Posts

  • 1 month later...

Cloning is not a simple procedure in JavaScript because of many factors including prototype chains. Your best bet is to create a new sprite and copy the properties you want over to it, i.e.: 

var sprite1 = game.add.sprite(100, 200, 'player', 0);var sprite1Copy = game.add.sprite(sprite1.x, sprite1.y, sprite1.key, sprite1.frame);

You'd then set any other properties you've already set on the original in the same way. If you're going to do this often and have lots of stuff to copy across, creating a function to do this would be the best approach.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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