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.