Page 1 of 1

2D reflection on water

Posted: Sat Apr 01, 2017 12:46 am
by Ducktor Cid
I'm trying to make a 2D reflection on water in my kind of luftrausers clone

My main problem is currently that the reflection comes off the water, as shown in this image

Here's my code for the reflection:

Code: Select all

	
playerClone.Position=Vector2.new(player.entity.Position.x, (2*water.Position.y-player.entity.Position.y)-50) --50 being the size of the image
playerClone.Rotation=-player.entity.Rotation
I'm not sure how to make it so the reflection doesn't clip. I tried using love.graphics.setScissor() but it seems to affect all of the graphic objects.

Does anyone know how I can do this?

Re: 2D reflection on water

Posted: Sat Apr 01, 2017 2:38 am
by yang
If the water is just confined to a rectangle, then love.graphics.setScissor() is your best bet.

What you want to do is enable scissor only when drawing the reflection, and disable it immediately after the reflection's been drawn by calling love.graphics.setScissor() with no arguments, so that no other objects will be affected.

Re: 2D reflection on water

Posted: Sat Apr 01, 2017 11:24 am
by Ducktor Cid
I'm using a camera system by blackbulletIV and I've noticed that scissor seems to not work correctly. (I go to the spot where the reflection should be, it isn't there but as I go away, I can start to see the reflection appear)

Is there any way to fix this, or do you know of any camera system that works with setScissor?

Re: 2D reflection on water

Posted: Sat Apr 01, 2017 2:22 pm
by Davidobot
Any camera library should work with setScissor. Make sure you're using your world coordinates for the scissor and remember to unset them after you're done.

Re: 2D reflection on water

Posted: Sat Apr 01, 2017 3:05 pm
by Ducktor Cid
I decided to use a stencil since I couldn't get scissor to work. Thanks for the help anyway!