[SOLVED] Where is my mouse positioned?

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
felsenstern
Regular
Posts: 72
Joined: Tue Jul 11, 2017 2:13 am
Contact:

[SOLVED] Where is my mouse positioned?

#1 Post by felsenstern »

Hiya,

is there a simple way to get the mouse cursor location inside a Ren'Py screen?
Last edited by felsenstern on Tue Nov 16, 2021 5:46 am, edited 1 time in total.
---
Yes, I've Read The F*cking Manual
Yes, I've used the f*cking search function
Yes, I've used a site search
No, I don't need a reminder that search functions exist
No, I don't need your astonished outbreak that I couldn't find the information
No, I don't need your answer if you can't just give it without all the BS around it

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Where is my mouse positioned?

#2 Post by philat »

https://www.renpy.org/doc/html/other.ht ... _mouse_pos

You can find several examples using this if you search the forums as well.

felsenstern
Regular
Posts: 72
Joined: Tue Jul 11, 2017 2:13 am
Contact:

Re: Where is my mouse positioned?

#3 Post by felsenstern »

philat wrote: Tue Nov 16, 2021 4:47 am You can find several examples using this if you search the forums as well.
Sometimes I wish you guys could see a log of all my search queries and pondering I've done before having to beg for information in this forum and of course getting exactly the RTF quote.

Thanks for the info anyways.
---
Yes, I've Read The F*cking Manual
Yes, I've used the f*cking search function
Yes, I've used a site search
No, I don't need a reminder that search functions exist
No, I don't need your astonished outbreak that I couldn't find the information
No, I don't need your answer if you can't just give it without all the BS around it

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: [SOLVED] Where is my mouse positioned?

#4 Post by philat »

Chill, dude. I meant the documentation doesn't show you how to use it, so if you need examples, search the forum. Obviously I have no idea what you searched for, but fyi the in-forum search isn't great and I tend to find google with site:lemmasoft.renai.us turns up better results. :shrug:

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: [SOLVED] Where is my mouse positioned?

#5 Post by zmook »

Here's the code I use, which I of course hacked together from code elsewhere on these forums:

Code: Select all

default mousex = 0
default mousey = 0

init python:

    # create a 1x1 invisible Displayable to listen for Mouse motion events
    # updates store.mouse_pos every time the mouse moves
    class getMousePosition(renpy.Displayable):

        def __init__(self):
            renpy.Displayable.__init__(self)

        def event(self, ev, x, y, st):
            import pygame

            if ev.type == pygame.MOUSEMOTION: # Updates the position of the mouse every time the player moves it
                store.mouse_pos = (x,y)
                renpy.restart_interaction()

        def render(self, width, height, st, at):
            return renpy.Render(1, 1)

    store.mousePosition= getMousePosition()

    def checkEvent():
        ui.add(mousePosition)
        
    if debug:
        config.overlay_functions.append(checkEvent) # This adds a 1*1 invisible displayable on every screen
Alternately, if you just want to know the position of a Drag:

Code: Select all

screen metadata_overlay():
            drag:
                pos start_pos
                dragged caption_dragged
                textbutton gallerytitle style "gallerytitle"

init python:
    def caption_dragged(drags,drop):
        renpy.log("dragged to %d,%d" % (drags[0].x,drags[0].y) )
        return None
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: No registered users