[SOLVED] Bug? get_physical_size() and get_mouse_pos() unexpected values with resized window.

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
__ess__
Newbie
Posts: 8
Joined: Mon Nov 01, 2021 4:13 am
Discord: __ess__
Contact:

[SOLVED] Bug? get_physical_size() and get_mouse_pos() unexpected values with resized window.

#1 Post by __ess__ »

Hello!

I have an issue with resizing the game window and getting accurate values from get_physical_size and get_mouse_pos functions and I'm unsure if I'm missing something or if this is a bug. Have been reading through some of the documentation pertaining this but haven't found anything that would explain this behaviour.

I have attached a small example project where anyone can test this if they want, but below is the code in it's entirety for this test.

Code: Select all

init python:
    def show_info():
        print("physical size = {}".format(renpy.get_physical_size()[0]))
        print("mouse pos = {}".format(renpy.get_mouse_pos()[0]))

screen my_screen:
    modal True

    key "K_SPACE" action Function(show_info)

label start:
    call screen my_screen
    return
With this test, I have a project size of 1280 x 720. In the test, I have a simple screen that aims to get a function to run every time one presses the space button on the keyboard. This function prints out the width of the game window and the x position of the mouse into the debug console.
In my test, I launch the game, resize the window to be maybe around 30 - 50% smaller, then press the start button of the game menu.
I then position my mouse in a location on the x-axis inside the game window, press space, then move to another location further to the right, press space etc., always within the game window.
Then afterwards, I check the log to see what has been printed out, and I find that even though I've always stayed inside the game window, the output shows the last time I pressed space, the x position of the mouse is a larger value than the actual size of the window.

Screenshot of the console below from one of these tests:
Image

I can't make any sense of why this happens. I'm trying to make this work in an actual project and have kind of hit a snag with the results of this. Does anyone know the reasons for this happening? Should I perhaps file this as a bug?

Thanks!
Attachments
test-project.zip
(745.57 KiB) Downloaded 14 times
Last edited by __ess__ on Wed May 25, 2022 6:30 am, edited 1 time in total.
:idea: Check out my Ren'Py mini-game tutorials on Youtube :idea:

__ess__
Newbie
Posts: 8
Joined: Mon Nov 01, 2021 4:13 am
Discord: __ess__
Contact:

Re: Bug? get_physical_size() and get_mouse_pos() unexpected values with resized window.

#2 Post by __ess__ »

Here's a gif showing the problem as well, using same code as my first post.

Image
:idea: Check out my Ren'Py mini-game tutorials on Youtube :idea:

User avatar
m_from_space
Miko-Class Veteran
Posts: 957
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Bug? get_physical_size() and get_mouse_pos() unexpected values with resized window.

#3 Post by m_from_space »

Well, if you have a project that's 1280 x 720 and then resize the window, the project (luckily) is still considered 1280 x 720, otherwise your images would not be part of the screen anymore if you set them at a position that is not relative to the screen and hotspots wouldn't work. I think it's working as intended.

get_mouse_pos() will always give you the position as if the player is doing it inside the intended screen, so you don't have to calculate anything. (Beware that if you check for mouse_pos and the player is not inside the window, the values are meaningless.)

__ess__
Newbie
Posts: 8
Joined: Mon Nov 01, 2021 4:13 am
Discord: __ess__
Contact:

Re: Bug? get_physical_size() and get_mouse_pos() unexpected values with resized window.

#4 Post by __ess__ »

m_from_space wrote: Wed May 25, 2022 4:28 am Well, if you have a project that's 1280 x 720 and then resize the window, the project (luckily) is still considered 1280 x 720, otherwise your images would not be part of the screen anymore if you set them at a position that is not relative to the screen and hotspots wouldn't work. I think it's working as intended.

get_mouse_pos() will always give you the position as if the player is doing it inside the intended screen, so you don't have to calculate anything. (Beware that if you check for mouse_pos and the player is not inside the window, the values are meaningless.)
Thanks for your response!
I might be a little slow this morning, so my apologies if I'm misunderstanding something. :)
I'm still not entirely sure I understand. get_physical_size gets the size of the game window rather than the project size, and get_mouse_pos gets the position of the mouse inside of the game. So if the window size is 1280 pixels wide, and if the mouse is flush against the left side of the game window (inside of it of course) the x coordinate shows 0. If the mouse is flush against the right side of the window, then the x coordinate shows 1280.
So if the size of the window is resized to 1060 pixels on the width, then the mouse still has an x coordinate of 0 on the left side and on the right side, it should now have a coordinate of 1060 if I'm not mistaken?

But if that is incorrect, am I understanding correctly then that the size of the actual project and its scale influences how Ren'Py calculates the position of the mouse with the get_mouse_pos function? So the mouse coordinates are not in relation the window but rather to the project, if that makes sense.

So with the example image below, the blue frame is the game window size, same as the project size, and the red frame is the resized window which has a new width.
Would this be correct?

Image
:idea: Check out my Ren'Py mini-game tutorials on Youtube :idea:

__ess__
Newbie
Posts: 8
Joined: Mon Nov 01, 2021 4:13 am
Discord: __ess__
Contact:

Re: Bug? get_physical_size() and get_mouse_pos() unexpected values with resized window.

#5 Post by __ess__ »

Just want to give an update to say that I adjusted my project to use the config.screen_width and config.screen_height instead to account for this behaviour to make it function as per my needs for my project. Thanks again for informing me @m_from_space. Perhaps this thread can be useful to others who may be wondering the same! :)
:idea: Check out my Ren'Py mini-game tutorials on Youtube :idea:

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Bug? get_physical_size() and get_mouse_pos() unexpected values with resized window.

#6 Post by Ocelot »

Yes, that is correct. Everything in RenPy always work as if game size is of project size, because otherwise absolute positioning would become extremely hard. There are only a few ways to break out of this and see different results. get_physical_size is one of them.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Google [Bot]