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

Map layer merging fix for distances does not optimally merge layers #126

Closed flurin closed 10 years ago

flurin commented 10 years ago

6c80228c9cb4873d2cda69f356123a619c43b155 fixed the issue with wrongly merged layers but now it does not optimally merge all possible layers.

In layer.js the fix was as such:

if ( item.preRender && !item.repeat && ( typeof lastDistance === 'undefined' || item.distance === lastDistance ) ) {

This however means if you have these layers:

sky(background, distance=2), bg(background, distance=1), main(background, distance=1), fg(foreground)

It would only start merging starting from the main layer and effectively create 4 maps instead of just 3 (sky, bg+main, fg).

I'll create a pull request with a fix.

collinhover commented 10 years ago

Oops, my fault on this one. Thanks for finding and providing a fix!