Croping&masking images

Hi all,

I am writing a mini-game. I show an image then I want to put a mask on it, so part of it will be black, and then I want to give 4 answers to the user and he must choose which answer is the black one.

Just like in this video:

http://www.youtube.com/watch?v=8PVjxst8s5g&t=275  

What is the best way to do this? All I’ve got is an image and different masks.

Hi @marcin.michalek,

Did you check out the guide on masking? This should get you started in the right direction:

http://docs.coronalabs.com/guide/media/imageMask/index.html

Sincerely,

Brent Sorrentino

Yes I did. In here it’s more complicated. I need to show only a part of an image and during mask creation I don’t know on which part the mask will apply on.

Is there any way to mask an image and then save only the invisible (black part of the mask) part it into a variable?

Hi @marcin.michalek,

Are you speaking about applying a mask, then “clipping” only the masked part of the image (or the non-masked part) and creating an entirely new image from it? In the video you show, is your app going to work very much like that?

Yes, exactly. ( the new image doesn’t have to be saved in a new file )

So I assume it isn’t possible yet?

Hi @marcin,

I did some testing on this and had some luck capturing the masked part of the image as a new file (image) on the screen. However, this method uses the capture methods in a way they’re not typically used for, so it may exhibit some slight behavioral differences on different devices. In your intended game, will it be arranged in the same “puzzle piece” kind of layout? If so, there may be another approach to this besides masking and display group capture…

Brent

Yes, it will use the puzzle layout. What approach could you recommend?

Hi @marcin,
In this case, I think you may try the following:

  1. create two display objects which are the entire puzzle image, overlaying each other exactly.
  2. create the required puzzle masks, so that you have the “shown piece” in white on the mask, and everything else black (so the outlying regions will be hidden).
  3. for the proper piece to be shown, apply that mask to the front image.
  4. at the same time, place a black vector rectangle between the front image and back image, starting at alpha of 0.
  5. transition that rectangle to around 90% opacity in a transition, so that the back image appears darkened out, while the front (masked) piece remains illuminated.

There will be some other interesting methods available in the upcoming Graphics 2.0 engine, including the ability to apply Photoshop-like filter and blending effects (like darken) to display objects.

Sincerely,
Brent Sorrentino

Hi @marcin.michalek,

Did you check out the guide on masking? This should get you started in the right direction:

http://docs.coronalabs.com/guide/media/imageMask/index.html

Sincerely,

Brent Sorrentino

Yes I did. In here it’s more complicated. I need to show only a part of an image and during mask creation I don’t know on which part the mask will apply on.

Is there any way to mask an image and then save only the invisible (black part of the mask) part it into a variable?

Hi @marcin.michalek,

Are you speaking about applying a mask, then “clipping” only the masked part of the image (or the non-masked part) and creating an entirely new image from it? In the video you show, is your app going to work very much like that?

Yes, exactly. ( the new image doesn’t have to be saved in a new file )

So I assume it isn’t possible yet?

Hi @marcin,

I did some testing on this and had some luck capturing the masked part of the image as a new file (image) on the screen. However, this method uses the capture methods in a way they’re not typically used for, so it may exhibit some slight behavioral differences on different devices. In your intended game, will it be arranged in the same “puzzle piece” kind of layout? If so, there may be another approach to this besides masking and display group capture…

Brent

Yes, it will use the puzzle layout. What approach could you recommend?

Hi @marcin,
In this case, I think you may try the following:

  1. create two display objects which are the entire puzzle image, overlaying each other exactly.
  2. create the required puzzle masks, so that you have the “shown piece” in white on the mask, and everything else black (so the outlying regions will be hidden).
  3. for the proper piece to be shown, apply that mask to the front image.
  4. at the same time, place a black vector rectangle between the front image and back image, starting at alpha of 0.
  5. transition that rectangle to around 90% opacity in a transition, so that the back image appears darkened out, while the front (masked) piece remains illuminated.

There will be some other interesting methods available in the upcoming Graphics 2.0 engine, including the ability to apply Photoshop-like filter and blending effects (like darken) to display objects.

Sincerely,
Brent Sorrentino