View Full Version : how do I clone a sprite?
joshchernoff
January 26th, 2008, 01:50 AM
how do I clone a sprite?
example..
var s1:Sprite = new Sprite();
var s2:Sprite = s1.clone();
Dazzer
January 26th, 2008, 02:36 AM
If you need an exact copy, you can try a deep-copy. But even that has problems.
Other than that you don't really have much options other than storing some variables, and implementing your own clone method in a custom class.
mprzybylski
January 26th, 2008, 09:07 PM
yeah, i'd probably make a custom class and just do it like that.
joshchernoff
January 26th, 2008, 11:22 PM
It's strange to think that this is not a built in function....?
Dazzer
January 27th, 2008, 12:09 AM
There is. "New".
The thing about "cloning" is that there are a couple of ways to look at it.
Do you want another instance of a class? Or do you want an exact clone as it is now? If you're cloning a Sprite, how about internal data that is put there at run time? Say using the Graphics object? Do you clone that?
Make a Custom Class, and implement your own function. ^^
daleth
January 27th, 2008, 03:52 PM
Exactly. Since Sprite is a static class and you can't define new properties and methods for it anyway, ultimately it's best to just make a new class that extends Sprite. It might seem like the "long way around" at first, but it solves so many problems down the road.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.