collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

Cutting off entities outside the level? #124

Closed Pattentrick closed 10 years ago

Pattentrick commented 10 years ago

Hi @collinhover,

i am working on an ingame cutscene right now. This may be a little hard to explain:

http://www.shuchu.de/ssr/

When the bees are leaving the level they don't get "cut off" and are still fully visible. That looks a bit silly. Is this the expected behavior, or could i do something about that? I just could kill the bees, once they reached the level border, but i want them to be "cut off" and be partial visible, when they leave the level.

I don't want to spoil the story for you, but the snail will get abducted by aliens. So later on i will spawn a big UFO above the level, which slowly flies down to the snail, abducts it, and flies away (outside the level). The problem would be, that the UFO is visible before entering the level and after that (before i kill it).

Is there a built in way to hide everything outside the level? And also on a partial basis? For example, if the upper half of the UFO leaves the level, allow the lower half to be still visible in the process?

I could create a big black entity with a higher zIndex than the UFO (and/or the bees) and place it on top of the level, which does that. But that seems a bit hacky, what do you think?

collinhover commented 10 years ago

Haha, poor snail!

There is nothing in place to handle this sort of masking or cropping. The fastest way to handle this would be to create a cropping area yourself as you suggested. If you wanted a more dynamic way to do it, you could do a intersection test with the entity bounding box against the polygon shape of the level (as extracted by the shapesPasses), but this seems extraordinarily expensive. There is likely a cheaper way, but I'd recommend the simple cropping shape in a foreground layer above the entities layer.

Pattentrick commented 10 years ago

it's not easy these days to be a snail :D

I will do the solution with the foreground layer above the entities layer. Thanks for your advice!