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.
I'm trying to make a screen where I need to get mouse position when the player clicks the mouse (or touches the screen if on Android), to then show a small click animation on that position. Browsing through the documentation I found renpy.get_mouse_pos() and it seems to be what I need. I made a screen to test and placed a variable to store and use the tuple this function returns, and I've encountered a strange problem while using it.
When I call the screen, the initial mouse position is shown on the variable, but then when I click it doesn't immediately update. I need to double click for some reason for the variable to update on the screen, and even then sometimes it shows an old position of the mouse instead of current.
Divona wrote: ↑Mon Oct 09, 2017 10:45 am
try to do it outside?
Yes, that works! I had originally planned to do it from outside but I read somewhere in this forum that it was better to do things locally if possible, but it seems better to do it globally for this case.
Oddly enough, when I added the show animation code to the key statement, getting the mouse pos started slowing down again unless I double clicked. I started tinkering with it once again and I stumbled upon what seems to be a solution: adding a mouse_up event along with the mouse_down seems to fix the slowdown issue. I haven't encountered any other problems with this so far, only thing left for me to do is to add the anim but that should be easy enough.
With 'mouseup' method, player can hold left mouse and drag, when releases the spark show up at the wrong place. Here is another option using timer to get mouse position at all time:
I realized this just yesterday, hadn't come up with a solution yet but timer looks like a fine solution, I didn't know it could be used like that, it works wonderfully.
Only problem left is that the animation doesn't show up above buttons and other clickable areas, but that is to be expected since putting this screen on a higher layer than others would probably make them unable to capture the mouse click. Right?
Once again thanks for your help Divona, I've learned a lot from this and other posts of yours out there, you're amazing!