Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make a mirror reflection of an entity in Flashpunk. So I would like to copy a spritemap from one Entity to another (reflectionEntity). If i use something like this

reflectionEntity.sprite = otherEntity.sprite;

reflectionEntity.sprite.scaleY=-1; // to reflect

then the graphic of the original entity is also scaled.

Is there a simple way out of this? I have been searching for the solution for more than an hour and have not found a suitable one.

share|improve this question

I'm assuming that reflectionEntity.sprite is an instance of Image or TiledSpriteMap. In the constructor for Image there's a souce:* parameter where you specify where the image comes from. This is the data you want to share.

Copying reflectionEntity.sprite (again, assuming that this is something like Image, or any subclass of Graphic really) just copies the references to that, which is why your changes propagate.

Flashpunk keeps an internal reference to the source, as seen here, but has it marked protected for whatever weird reason.

Keep the reference to whatever object you use to load your image, and pass that into a new instance like so:

[however the embed statement is written goes here, I forget]
var yourSpriteSource:Class; // Class, assuming you're doing resource embedding
otherEntity.sprite = new Image(yourSpriteSource);
reflectionEntity.sprite = new Image(yourSpriteSource);

Another alternative is to subclass each Graphic class you're interested in and expose the source() function. Another alternative to that (which is likely what I would do on a project), is fork Flashpunk and make the source() function public. But that's a bit extreme.

Think of Graphic subclasses as bits of data that know how to render the real graphics data, which is the source parameter you pass into their constructor.

share|improve this answer
Thank you very much for the suggestion, probably this is how I am going to do this, I was looking for a simpler (and more elegant) solution, but I guess I will copy the source image and manually set the frames. – James Mar 9 '13 at 12:03
@James If you want to make it more elegant, extend Image/TiledSpriteMap/whatever you're using and write a clone() method for it that also sets the frames for the new clone. – michael.bartnett Mar 9 '13 at 18:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.