Need help understanding masks

From the posts on this site, it seems that many Corona developers come from the Flash, gaming or related worlds. For those of us who don’t (my background is in headless server apps), things like reference points, xOrigin, xReference, X, tiles and bitmap-masks initially feel a bit daunting & the docs presume that you know what these things are about.

I’m trying to make an object disappear behind an INVISIBLE object. The invisible object (lets call it the “wall”) needs to be invisible so that the construct (an object) will work on any background that I place it over. And because this “wall” has a fixed edge, my object must disappear in increments as it’s Y coordinate changes…in other words, I can’t just set “isVisible” to false.

I would greatly appreciate any tips or examples (using masks I presume) from you experienced guys that show how to do such a thing.

In return, I share one of my favorite Lua tips that greatly simplifies the code for setting default params in your objects.

Instead of all this code:
[lua]if ( params.font ) then
font=params.font
else
font=native.systemFontBold
end

– you can do this
font = params.font or native.systemFontBold
– if params.font is nil, the value after “or” gets returned[/lua]

[import]uid: 6175 topic_id: 6151 reply_id: 306151[/import]

why are you not just adding your wall elements on a higher layer than your ground?

— roof layer
— player layer
— ground layer

when i say layer, in corona terms i mean a display group

are you using a single flat image for your map including building roofs/bridges etc rather than different layered tiles?

if so then this is how i’d do it: (theoretical so let me know if it works!)

* load your background image into your image editor
* create a new layer
* draw black over your roof/bridge objects
* disable the background image
* save your “mask” image (black areas) as mask.png
* in corona load bg.png twice and set mask.png to be the mask of the uppermost bg.png
* insert your player between the two bg.png layers

(i’ve assumed it’s using transparency in the mask rather than white… check the circlemask.png in the included flashlight example)

theoretically any areas that didnt have black in the mask will be transparent and show the copy of bg.png underneath, and any areas that did have black in the mask will not be transparent and therefore show the bridge/roof area etc

bg.png will only use texture memory for the 2 copies once.

i’ll put this in real world terms for clarification. print out 2 copies of your background map, take the topmost copy and cut out the areas that are pathways, grass etc, leaving behind the areas that are roofs, bridges etc. (ok you’re piece of paper will soon fall apart but you get the point!). If you place the 2 pieces of paper on top of each other, and then slie your player inbetween the two, you’ll see what the masking process I have defined above is doing.

I wouldn’t advise this for large maps though… but if it’s a single screen etc i guess it should be ok

currently I believe ansca have only allowed a png as a mask, not a dynamically generated image etc, so i’m not sure you’d be able to place multiple copies of a mask over certain areas to build up the transparent areas. it would be good if captureScreen could save a transparent PNG that you could create, save and reload as a mask though

regards
j

[import]uid: 6645 topic_id: 6151 reply_id: 21079[/import]

Thanks for the detailed response…I’m not even sure I have the graphical skills to do what you proposed but I will learn if that’s the only way…

I feel like I understand Corona groups pretty well, so perhaps I didn’t fully express that I want this object to be background independent…i.e. injectible over any existing screen without customization to that lower screen

The “layer” (display group) that represents the wall, needs to be INVISIBLE…it needs to let whatever is on the layer below (call it the base-layer) show through.

If I can avoid it, I don’t want to split all of my base-layer UI into separate groups, just to allow this one object to fly it’s elements behind one of those groups…that would make a lot of my other coding very complex.

The “date-picker” wheel on the iPhone is a good example…when you roll the dates, they disappear behind the rest of the screen…I’m trying to create something similar in a “background independent” manner so I can float such an object over any screen without having to pre-plan it’s layers as separate groups. Does that make sense? Perhaps it’s not possible? [import]uid: 6175 topic_id: 6151 reply_id: 21084[/import]

i’ll put in a feature request for a dynamic mask. even just being able to draw it, saving as a png with transparency and reload as a mask would help…

maybe this stuff is coming later though anyway

with the date picker though it’s only ever on a black background etc. you could just cut out this shape as a PNG in the first place to stick over the picker, and then have another mask over the picker to stop the numbers appearing outside your overlay. [import]uid: 6645 topic_id: 6151 reply_id: 21086[/import]