slice a bitmap/sprite

3 posts (showing 1-3)
pranadevil

Market Level 0Community Level 3
133 posts

hi everyone, stop here asking for wisdom.

do you know how in this life can a bitmap or sprite be sliced, using the mouse for example?

i mean i can draw the line but cant figure it out yet how can i slice the sprite using this line?

any code well explain will be very helpful thanks!

posted 2016-08-19T20:07:05-07:00
JohnBlackburne

Market Level 3Community Level 10
2184 posts

You can, but it‘s a multistep process. First you can draw anything to a BitmapData draw() call, so whether you start with a Bitmap or Sprite get it into a BitmapData if it isn’t there already.

Then you want to use copyPixels. This normally just copies pixels quickly from one BitmapData to another. But you can tell it which pixels to copy by supplying a Rectangle or a mask in the alphaBitmapData parameter.

So what you need to do is create a mask from your slice. You can use the Graphics class for this, combining your line with others to make a shape with beginFill and endFill so it fills in the pixels. Draw this into a BitmapData then use that in the alphaBitmapData parameter of copyPixels to create a slice. Repeat with other masks to create more slices.

That sounds like a lot of work but it’s actually only a few function calls that do all the heavy lifting. The most work is creating the shape as a Graphics object, but you may already have most of the code for that. Read up on the draw() and copyPixels() functions in the BitmapData class as they are quite powerful and flexible and should be part of every developer’s toolkit.

posted 2016-08-20T17:52:19-07:00 | edited 2016-08-20T17:57:25-07:00
pranadevil

Market Level 0Community Level 3
133 posts

ill try it thanks

posted 2016-08-21T18:20:43-07:00