shadow that might require some masking. Not sure on Corona capabilities with masks

I’ll try make it simple

  • imagine a deep-space background with distant stars. 

  • foreground is populated by planets

  • planets cast shadows that extend way out which is essentially a black shape with transparency.

The problem is I only want this “shadow zone” to cover any objects in the foreground (like the blob player) and NOT the space beyond in the background.

Basically can I make a display object only appear while it intersects with another? As in I want that black box in the image attached to only appear when a foreground object intersects with it. I imagine this is not possible? The masking features are pretty primitive right? especially since the character is actually drawn with code…
 

It sounds like what you actually want is to place shadows on top of the foreground objects?  

Rather than masking a shadow object in certain places at runtime, could you not just create a shadow object for each foreground object and make that visible when needed. You’d just need an additional newImageRect which uses the same image as the foreground object, and uses setFillColor(0, someAlphaValue). 

That would also then allow you to change the strength of the shadow on each foreground objects based on the distance from a given point.

Edit: 

If you don’t want to manage lots of shadows separately, then you might be able to achieve your original plan using blendModes: 

https://docs.coronalabs.com/api/type/Paint/blendMode.html

It’s been a while since I used those though, so can’t remember what limitations they may have.

Basically can I make a display object only appear while it intersects with another? As in I want that black box in the image attached to only appear when a foreground object intersects with it.

In order to accomplish this, couldn’t you just track collisions with the ship and the shadow(s)? You can do this with or without physics. When the collision begins, the ship enters the shadow and you can transition them from transparent to whatever alpha value you need. Once the collision ends, i.e. the ship moves out of the shadow, then just transition them back to transparent.

It sounds like what you actually want is to place shadows on top of the foreground objects?  

Rather than masking a shadow object in certain places at runtime, could you not just create a shadow object for each foreground object and make that visible when needed. You’d just need an additional newImageRect which uses the same image as the foreground object, and uses setFillColor(0, someAlphaValue). 

That would also then allow you to change the strength of the shadow on each foreground objects based on the distance from a given point.

Edit: 

If you don’t want to manage lots of shadows separately, then you might be able to achieve your original plan using blendModes: 

https://docs.coronalabs.com/api/type/Paint/blendMode.html

It’s been a while since I used those though, so can’t remember what limitations they may have.

Basically can I make a display object only appear while it intersects with another? As in I want that black box in the image attached to only appear when a foreground object intersects with it.

In order to accomplish this, couldn’t you just track collisions with the ship and the shadow(s)? You can do this with or without physics. When the collision begins, the ship enters the shadow and you can transition them from transparent to whatever alpha value you need. Once the collision ends, i.e. the ship moves out of the shadow, then just transition them back to transparent.