2D reflection on water

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Ducktor Cid
Prole
Posts: 18
Joined: Wed Oct 05, 2016 8:08 pm

2D reflection on water

Post 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?
User avatar
yang
Prole
Posts: 3
Joined: Wed Mar 29, 2017 11:10 pm

Re: 2D reflection on water

Post 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.
User avatar
Ducktor Cid
Prole
Posts: 18
Joined: Wed Oct 05, 2016 8:08 pm

Re: 2D reflection on water

Post 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?
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: 2D reflection on water

Post 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.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Ducktor Cid
Prole
Posts: 18
Joined: Wed Oct 05, 2016 8:08 pm

Re: 2D reflection on water

Post by Ducktor Cid »

I decided to use a stencil since I couldn't get scissor to work. Thanks for the help anyway!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests