• To improve security, we will soon start forcing password resets for any account that uses a weak password on the next login. If you have a weak password or a defunct email, please update it now to prevent future disruption.

VN Ren'Py Mouse pointer changing

VIGOR GAMES

Member
Game Developer
Feb 27, 2021
185
1,458
Hello everyone,

I have a problem with changing cursor in mid game....

I need change mouse pointer to zoomer for a while and then change it back to standart cursor.

I'm using this code, but it doesnt work properly.

Code:
init python:
    def change_cursor(type="default"):
        persistent.mouse = type
        if type == "default":
            setattr(config, "mouse", None)
        elif type == "1":
            setattr(config, "mouse", {"default": [("images/1.png", 0, 0)]})
        elif type == "2":
            setattr(config, "mouse", {"default": [("images/2.png", 0, 0)]})

    if not hasattr(persistent, "mouse"):
        change_cursor()
    else:
        change_cursor(persistent.mouse)
Code:
    $ change_cursor("1") #Here cursor must change to zoomer
    
    elina "Some text"
    
    scene w058_1

    elina "Some text"
    
    $ change_cursor() #Here cursor must change to standart
 

AnimeKing314

Giant Perv
Game Developer
Jun 28, 2018
395
595
Can you give a little more detail on how it isn't working. Does it do the first change and not the second or does it just not change at all?
 

VIGOR GAMES

Member
Game Developer
Feb 27, 2021
185
1,458
Can you give a little more detail on how it isn't working. Does it do the first change and not the second or does it just not change at all?
It do first change in main menu before the game starts.... The second change doesn't happen..
Снимок экрана 2021-04-29 130935.jpg

In the console confing.mouse = None, but cursor still not standart
 

AnimeKing314

Giant Perv
Game Developer
Jun 28, 2018
395
595
It do first change in main menu before the game starts.... The second change doesn't happen..
View attachment 1169382

In the console confing.mouse = None, but cursor still not standart
So the first thing is, since you only want the mouse to change in specific parts of the story I recommend not making the variable persistent. This is likely what's causing it to change in the main menu. Also try turning init python: to init +1 python: as this will make that init block run later (it's possible that your init block is running before the normal renpy code that sets up the mouse pointer which might be causing the issue). I'm not sure if either of these will work, if not I'll try testing out a few ideas myself to see if I can figure it out.
 

VIGOR GAMES

Member
Game Developer
Feb 27, 2021
185
1,458
So the first thing is, since you only want the mouse to change in specific parts of the story I recommend not making the variable persistent. This is likely what's causing it to change in the main menu. Also try turning init python: to init +1 python: as this will make that init block run later (it's possible that your init block is running before the normal renpy code that sets up the mouse pointer which might be causing the issue). I'm not sure if either of these will work, if not I'll try testing out a few ideas myself to see if I can figure it out.
When i use this code cursor doesn't change

Code:
init +1 python:
    def change_cursor(name="default"):
        if name == "default":
            setattr(config, "mouse", None)
        elif name == "1":
            setattr(config, "mouse", {"default": [("images/cursor_zoomer.png", 0, 0)]})
But in console everything is ok ...
Снимок экрана 2021-04-29 130935.jpg
 

AnimeKing314

Giant Perv
Game Developer
Jun 28, 2018
395
595
So I've done some playing around with a few different options and tried to find different solutions that worked for other people but I think those worked in older versions of ren'py. The info I found says that any config variable isn't meant to be changed outside of an init block (as in changing it before the GUI loads, not in a function that was defined in an init block). One possible solution is to have a separate custom pointer as the default and use the zoomer one in an imagemap. It's a bit of an ugly solution but I tested it and it works:
Python:
screen change_cursor():
    imagemap:
        idle "transparent.png"
        hover "transparent.png"
        hotspot (0,0,1920,1080):
            mouse "imagemap"
            focus_mask None
            action[Return()]
init python:
    config.mouse = {"default" : [("gui/default_cursor.png",0,0)],"imagemap" : [("gui/cursor_zoomer.png",0,0)]}

label start:
    scene example:
        fit "contain"
    "Some text"
    show screen change_cursor
    "cursor should now be changed"
    "sgbrbr"
    hide screen change_cursor
    "cursor should now be changed back"
    pause
 

VIGOR GAMES

Member
Game Developer
Feb 27, 2021
185
1,458
So I've done some playing around with a few different options and tried to find different solutions that worked for other people but I think those worked in older versions of ren'py. The info I found says that any config variable isn't meant to be changed outside of an init block (as in changing it before the GUI loads, not in a function that was defined in an init block). One possible solution is to have a separate custom pointer as the default and use the zoomer one in an imagemap. It's a bit of an ugly solution but I tested it and it works:
Python:
screen change_cursor():
    imagemap:
        idle "transparent.png"
        hover "transparent.png"
        hotspot (0,0,1920,1080):
            mouse "imagemap"
            focus_mask None
            action[Return()]
init python:
    config.mouse = {"default" : [("gui/default_cursor.png",0,0)],"imagemap" : [("gui/cursor_zoomer.png",0,0)]}

label start:
    scene example:
        fit "contain"
    "Some text"
    show screen change_cursor
    "cursor should now be changed"
    "sgbrbr"
    hide screen change_cursor
    "cursor should now be changed back"
    pause
Thank you, it helped me.