-
copy pixels
This is driving me mad. All I want to do is copy pixels or clone pixels from one Sprite into another empty sprite. I can get it to do it but it brings the data in as a square. I basically have a Sprite with a circle bitmap inside it. well its a png so its got transparency.
Below half works. But its also so much code to just get a copy of one sprite to another.
Actionscript Code:
var bmd:BitmapData = new BitmapData(button.model.width, button.model.height); bmd.draw( button ); var newBmd:BitmapData = new BitmapData( bmd.width, bmd.height); newBmd.copyPixels(bmd, bmd.rect, new Point(0,0), null,null,true ); var bitmap:Bitmap = new Bitmap( newBmd );
-
Do you really need a separate bitmap data? If you don't, then you can just use bmd to back your bitmap. No nead to create newBmd.
Also, since you appear to be copying everything, even if you do need a separate bitmapdata, you could use the clone method.
And finally, I'm not seeing a second Sprite, assuming that button is the first Sprite.
-
Yea I might not need a second bitmapData.
YEs button is the Sprite with my png inside it.
What that how can I create a clone of this that still holds its transparency.
-
As it stands, it looks like that should preserve the transparency. But you won't have a Sprite at the end, you'll have a Bitmap.
If your button is in your library, then you could export it for actionscript, give it a class name, then just create a new instance of it.
Code:
var button2:MyButton = new MyButton();
That will create another instance of it as it exists in the library.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|