Change sprite colour when entering water

Hi,

I have a water texture that is transparent, this is drawn before the player sprite, when player enters the water I want the player to appear behind the water so to speak - now I’ve done this at the moment by detecting when in water and just draw player first then water but if player is halfway in the water, the players bottom half which is in the water is still drawn on top of the water. I guess the obvious thing to do is always draw the player first?

Thanks

Hi,

That’s what i would do, i would draw the player first then draw the water over it, for your reasons, but always drawing the player first might not be a good idea if you want to add next particular things that are always displayed behind the player. But also because that in real world water is also transparent, and i think that using a transparent texture would feel more realistic.

The other alternative is using drawing layers, and you avoid doing any checks and furthermore you easily manage depth.
Example :

    1. Draw the background layer
    1. Draw the player
    1. Draw the water

Hi,

Did that and now appearing in water is fine, but player now disappears behind other blocks as these are part of the map the water is in…so all this is
rendered after the player as seen in screen below:

The water tiles are part of the same array as the other blocks, i.e. they are part of the same map.

This is why I coded it firstly to check if player was in water, if was, I rendered player after the rendering of the map, otherwise I rendered the player before drawing
the map, but of course, this doesn’t work very well, i.e. if head is out of water, whole player is drawn after the map is rendered.

All I can think of is to render tile map, then player and then somehow the water, but like I said, the water is part of the world map…(2d array).

Any ideas?

Thanks

Fixed. When drawing my map, checked if tile was instance of water, if so, player was drawn first, well kind of like this without going
into too much detail ;D

That’s a nice render you have there, except that the lamp light isn’t stopped by blocks. But is it me or can you actually see clouds behind the water ? Like just on the right of the player after the blocks that sould stop the lamp light ?

Well, for layers, let me give you a few more details. You could use some kind of buffering, i mean you use a first bufferimage where you draw “background tiles”, then a second on which you draw entities and third on which you draw liquids such as water. Then to render on screen you just first draw background image, then entities image, then liquids image. ( This idea of implementation might not suit best your game but clearly makes sense if you want to add many different blocks/liquids/entities without checking every time what you need to draw first)

Hi,

Yes, ignore the clouds behind the water at the moment, they won’t be drawn when so far down in
the map or I possibly draw extra tiles behind each water block.

The torch light is a box2dlight object, so not sure if can detect it hitting blocks when not
using box2d objects which I don’t. I could implement my own ray cast for the torch or just not bother
with the one you see here as having a torch lights up the area around the player anyway.

Thanks