[Solved] How can I create a functioning magnify glass in gdev

Recently I want to try making point ‘n’ click game on gdev and one of the problem I encountered is how to create a magnify glass in the game. I want it to zoom the object behind the lens which is like this

I hope you guys can help me.

While I haven’t personally used cameras before in GDevelop, I imagine this would utilise them. This wiki page about cameras even mentions zooming: Layers and cameras [GDevelop wiki]

1 Like

Hi, aside from what BWPanda suggested with the cameras, I have two more suggestions that could point you in the right direction.

  1. You could have the image that you want to look at with the magnifying glass on the left side and an enlarged version of the same image on the right side but in connection with the SpriteMasking-extension. You can connect the movement of your small rectangle on the left side with the masking sprite on the right which would make parts of the enlarged image visible. It could look like this:


    (I just put it very quickly together and the scene is not properly set up, but with some better alignments it might work quite well).

  2. You could also use a displacement-effect. You need a displacement map that looks like a lens and the result could look like this:


    The effect is quite good, the problem is that it affects the entire layer and since the lens is not moving you would need to move the actual image around.
    Effects can be also applied to objects but I did not manage to get it working, but it could be worth a try.

1 Like

Hello @T.X.T
A point’n’click, wow,; I love that kind of game.

My 5cents propose:
example:
the game is on “LAstandard” layer
create a new layer (name LAbackground) below “LAstandard” and without any image.
when you want to activate the magnyfy glass:

  • create a screenshot ( using the extansion) and put the image on the layer LAbackground
  • zoom the camera on the layer LAstandard

or

modify the flower image putting it before a below and enlarge it.

Regards,
J

2 Likes

thanks you it is a great idea but do not work specific in mys case still thank you for helping me I can use this mechanism for latter if I have any chance :slight_smile:

I am pretty interest in the 2nd picture result, can you show me the code you use for this

Thanks you I also try some camera zoom effect but it do not give the distorted effect I wanted but still thanks you to help me out :slight_smile:

It is actually quite easy. You apply a displacement -effect to a layer.

Then you need a displacement mask, which works like a lens. You could use this image here:
displacement_lens

You can adjust the size of the lens according to your preferences, you just have to make sure that the entire background of the lens is as big as your viewport, otherwise the lens-image will be tiled and you have several lenses instead of one. Of course, the lens does not need to be in the center, you could place it in a corner etc.

The tricky thing is that this effect is static, so in order to get the magnifying effect on different areas of the image, I made the image draggable and moved it around. I guess with some sprites on a layer in the foreground, maybe also using SpriteMasking, this could be okay, but it is different from moving a magnifyingGlass-object over the image.

As mentioned, there is also the possibility to apply the displacement-effect to an object (under “edit object” → effects-tab), I just did not really try to understand how this can be set up to have a magnifyingGlass-object, but it is definitely worth to look into this a bit more. If you would get this to work, it is probably exactly what you want.

1 Like

Can you tell me what displacement texture and offset did you use for your previous 2nd example picture I try to it and have my back ground to cover the whole viewport but the image is till be tiled and the glass is kind da half-way rendered

I add the object masking extension I use the lens picture you provide as a mask for the picture and I wonder if that the error

I used the same displacement map but I added a larger field of background to the map so that it has the size of the viewport. It looks something like that:
Capture_lens2
Just for understanding the problem: is the displacement effect on the layer?

The displacement mask is probably not ideal for the masking. It would be better to use another sprite in red, just a flat color.

1 Like

Thanks you very much I got what I needed


Still there some tiled parts of the picture at the rear is there any way to get rid of it ?

1 Like

You mean tiled lenses?

No I meant that the are strip part in the picture and is there any way to get rip of them ?

Ah I see. I thought that’s something you intended to have there. I am not really sure what the reason for this is.

Well thanks you anyway, you help me alot this time, I really appreciate. I kinda almost switch to godot and start everything from scratch but you save my day, thanks bro

I am glad that I saved you from that ordeal. :laughing:

Good luck with your project.

1 Like