04-21-2011 12:18 PM
Is there any way to restrict an image object to only draw within its bounds? I know you can use a mask, but it is for a gmae and it would degrade performance to have to mask each redraw.
Solved! Go to Solution.
04-21-2011 01:28 PM
hey CMY,
assuming you meant that you want to crop an image, this site can help you out:
http://blog.stroep.nl/2009/05/how-to-crop/
good luck!
04-21-2011 03:41 PM
I've seen that article but I was hoping there was a way to do it without having to crop the image every frame.
04-21-2011 04:07 PM - edited 04-21-2011 04:09 PM
Are you talking about an animated spriteSheet or something?
copyPixels() is probably what you want, or graphics.beginBitmapFill(), both are pretty similar in performance (fast) and memory usage (low).
Basically, you'll draw a target area from a source bmpData, into a target bmpData. You can cache the bitmapData each time, and once you've copied the whole animation into memory, then you can just update bitmap.bitmapData property each frame.
04-21-2011 07:45 PM
I'm not really sure what you are saying, but I'll look into it. The game I am designing allows two people to play at once and each user has their own playing surface that is drawn into, but the one that is on top also shows its animation over the top of the bottom one if any of it falls outside the bounds of the container. That it what I want to clip off, I don't want it to draw anything outside the bounds. In the java graphics object on BlackBerry smartphones its as simple as setting up a clipping rect to remove anything outside the bounds..
04-21-2011 08:11 PM
04-21-2011 11:39 PM - edited 04-21-2011 11:41 PM
Yep, you can do it 2 ways, set .mask to any displayObject, or set .scrollRect = new Rectangle(x,y,w,h);
You'll want to test which is best, but masking seems to be faster in general on playbook (everywhere else, scrollRect is generally the way to go unless you need a non-rectangular shape, or some alpha blending)