Zoom in and center at cursor position? [Solved!]

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
omranpanda
Newbie
Posts: 15
Joined: Tue Nov 03, 2020 4:29 pm
Contact:

Zoom in and center at cursor position? [Solved!]

#1 Post by omranpanda »

Hello!

As what the title says.
Does anyone know of a way to make it so that using the renpy.get_mouse_pos() function and the zoom ATL to zoom in and center at the mouse position?
Last edited by omranpanda on Sat Sep 11, 2021 3:51 pm, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Zoom in and center at cursor position?

#2 Post by Alex »

omranpanda wrote: Fri Sep 03, 2021 3:52 pm Hello!

As what the title says.
Does anyone know of a way to make it so that using the renpy.get_mouse_pos() function and the zoom ATL to zoom in and center at the mouse position?
Check this recipe - viewtopic.php?f=51&t=62550

omranpanda
Newbie
Posts: 15
Joined: Tue Nov 03, 2020 4:29 pm
Contact:

Re: Zoom in and center at cursor position?

#3 Post by omranpanda »

Alex wrote: Fri Sep 03, 2021 5:51 pm
omranpanda wrote: Fri Sep 03, 2021 3:52 pm Hello!

As what the title says.
Does anyone know of a way to make it so that using the renpy.get_mouse_pos() function and the zoom ATL to zoom in and center at the mouse position?
Check this recipe - viewtopic.php?f=51&t=62550
Thanks for this, however this is kinda too overkill for what I needed (And I was unable to implement it for my use case ;!;).

After spending a couple of days I was able to create the equation to solve this problem!

Basically this is what I got and it works perfectly for me. Sorry if my comments are bad ;!;

Code: Select all

python:
        curx, cury = renpy.get_mouse_pos() ## Get cursor position and store in x and y variables.

        zoom_factor = 4.0 ## Must be a float number. 4.0 zoom factor means that the image would be enlarged by 4 times, numbers smaller than 1.0 such as 0.5 could be
                          ## used to shrink instead of enlarge.

	## Adjust for the displacement caused by the zooming and cursor position.
        dx = (config.screen_width/2) - int(curx*zoom_factor)
        dy = (config.screen_height/2) - int(cury*zoom_factor) ## int function used because pixels can't be in float (You can't have half a pixel :p)

camera:

        parallel:
            linear 2.0 zoom zoom_factor

        parallel:
            linear 2.0 pos(dx, dy)




Post Reply

Who is online

Users browsing this forum: No registered users