How do I create a mirrored reflection?

Get help using Construct 2

Post » Thu Feb 04, 2016 5:20 pm

Currently I have created a second layer where I show mirrored versions of all objects that are on layer 1, but this actually requires twice as many cycles and it's a mess to handle all of the stuff that is going on in the reflection (I basically have to add each event twice and there might be hundreds of sprites to reflect etc). There must be an easier way using some of the effects, seeing that the advanced pixel shader in the "Glass" effect can modify the background. I'd basically require an effect where I can capture a piece of the screen and negative scale it for a reflection, or similar. Any ideas for this?

Thanks :)

Image
B
6
Posts: 34
Reputation: 318

Post » Thu Feb 04, 2016 6:13 pm

Look at the canvas or paster plugins. A search will also give some examples of doing this.
B
91
S
31
G
99
Posts: 5,192
Reputation: 65,670

Post » Thu Feb 04, 2016 7:17 pm

Thank you R0J0hound,

I installed paster and created a paster object, but I seem to fail to use it. I searched for a manual on how to use it, but failed there as well :(

I appreciate the time and effort you took to answer though!

Edit: Downloading a simple capx example you provided was enough to understand the underlying technique. Thanks!
B
6
Posts: 34
Reputation: 318

Post » Thu Feb 04, 2016 7:25 pm

The simplest way is to place the paster object where you want the water to be, then make an event like this:

every tick
--- paster: clear to rgba(0,0,0,0)
--- paster: set height to -self.height
--- paster: paste smileSprite
--- paster: set height to -self.height

and that's it. If you have multiple objects you want to reflect put more paste actions in there.

A slightly more deluxe method that reflects an entire layer would be this:
viewtopic.php?f=147&t=164456&p=995191&hilit=zindex#p995191
B
91
S
31
G
99
Posts: 5,192
Reputation: 65,670

Post » Thu Feb 04, 2016 7:43 pm

Oh ok, I see. I need to paste for each element in my sprite list a copy onto the paster. I thought that this problem could've been solved with a simple shader like

Code: Select all
varying mediump vec2 vTex;
uniform lowp sampler2D samplerBack;

void main(void)
{
    gl_FragColor = texture2D(samplerBack, vec2(vTex.x, abs(1.0 - vTex.y)));
}


But while this seemed to have some sort of effect in the ingame editor, it did nothing in the browser and I still wonder why :/
B
6
Posts: 34
Reputation: 318

Post » Thu Feb 04, 2016 9:08 pm

If it's not working in the browser then it's not using webgl. Your card is blacklisted or something.
B
91
S
31
G
99
Posts: 5,192
Reputation: 65,670

Post » Fri Feb 05, 2016 6:27 pm

Well if I add a simple sprite with a glass effect on the same layer, the effect suddenly works though, which is rather strange. All other effects work just fine.
B
6
Posts: 34
Reputation: 318


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot], giorgio1982 and 1 guest