Jump to content

Method to clone a sprite?


iamhaas
 Share

Recommended Posts

Is there a method to clone/duplicate a sprite?

 

Yes, I has same question too.

 

Because my Sprite, image, text is by user (alpha, rotate, scale).

 

I want to duplicate it.

 

How to make it ?

 

Thank you so much.

Link to comment
Share on other sites

  • 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...