Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon
Accepted Solution

Clipping an image?

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.

Highlighted
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Clipping an image?

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!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Clipping an image?

I've seen that article but I was hoping there was a way to do it without having to crop the image every frame.

Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Clipping an image?

[ Edited ]

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.

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Clipping an image?

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..

Developer
Posts: 144
Registered: ‎12-25-2010
My Device: PlayBook 16GB + Z10 LE
My Carrier: UfonePK

Re: Clipping an image?

Flash is a lot easier.

You can make a shape and and it as a mask to any MovieClip / Sprite on stage using "mask" property.

i.e. myGameMovieClip.mask = myMaskRect

I hope it helps,

// chall3ng3r //
--
- Our PlayBook Apps: IdeaPad | EasyCrop | Popcornia
- Free Icon Maker for BlackBerry PlayBook developers | 5900+ icons created and counting
- A Kudo is appreciated if you like my post Smiley Happy
- My post soveld the problem? Please click Accept as Solution.
Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Clipping an image?

[ Edited ]

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)