Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Ptg

So this follows on from the problem mentioned here:

http://impactjs.com/forums/help/entities-that-inconsistently-overlap

Of course now we have the autoSort and sortBy settings to easily overcome this issue between entities.

My problem is that I have the same requirements but also when it comes to 'foreground' map tiles. I.e. Entities below map tiles should be drawn above, while entities above tiles should be drawn behind them.

One option would be to make/convert map tiles into entities, but I am posting to see if there is perhaps a better alternative? I certainly want to continue using weltmeister to design the levels, and I am sure converting most map tiles to entities would be somewhat inefficient.

I am happy to dig into the code a bit and implement something, but I was wondering if other people already had a go at this type of thing?

1 decade ago by dominic

Currently, that's not possible with BackgroundMaps. They're either drawn behind all entities or in front of all entities.

One way to get around this limitation is to ensure that an entity can never overlap a tile which would in turn overlap the entity on another position. Have a look at this screenshot for example:
/><br />
<br />
The top of the trees can overlap sprites. However, the sprites can only overlap the bottom half of the tree. There's no way to reach a position in which the player can overlap the top half of the tree.<br />
<br />
To recreate this setup, put all tiles that overlap sprites on a foreground layer:<br />
<img src= var tilesY = ig.system.height / foregroundMap.tilesize; var e = 0; for( var y = 0; y < tilesY; y++ ) { // draw a line of the background map foregroundMap.drawLine( y ); // draw all entities that are on that tile line var maxY = y * foregroundMap.tilesize; while( this.entities[e].y < maxY && e < this.entities.length ) { this.entities[e].draw(); e++; } }
Of course you'll also have to take the screen position (and probably various edge cases!?) into account for this to work.

1 decade ago by Ptg

Great, thanks. Yep the last suggesting is the approach I was planning to go down pretty much. I do not want to have to consciously separate entity level map tiles into foreground/background.

To work with preRender, I guess I'll also have to mod it slightly so that the chunks are single line strips rather than squares, but that will be a secondary phase.
Page 1 of 1
« first « previous next › last »