[SOLVED] Custom mouse cursor in 7.4.x

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
sonejo
Newbie
Posts: 20
Joined: Thu Jun 30, 2016 4:00 pm
Contact:

[SOLVED] Custom mouse cursor in 7.4.x

#1 Post by sonejo »

Hi!

In my game I implemented a way to allow the user to switch between the system mouse cursor and a custom mouse cursor in the game's preferences. But since I switched to 7.4.x, this is not working anymore (as said in https://www.renpy.org/dev-doc/html/incompatible.html).
I had a look to docs, but I can't find a new way to implement this again. Is it still possible at all in 7.4.x? If, yes, how?

Thanks in advance,

Vince
Last edited by sonejo on Wed Jan 27, 2021 1:33 pm, edited 1 time in total.

Andy_kl
Newbie
Posts: 18
Joined: Sun Apr 09, 2017 12:00 pm
Contact:

Re: Custom mouse cursor in 7.4.x

#2 Post by Andy_kl »


User avatar
acorn-says-no
Regular
Posts: 30
Joined: Wed Jan 06, 2021 6:10 pm
Contact:

Re: Custom mouse cursor in 7.4.x

#3 Post by acorn-says-no »

Try this in gui.rpy

Code: Select all

define config.mouse = {"default":[ ("gui/cursor.png", 1, 1) ] }
Image
*CHAOS, CHAOS

sonejo
Newbie
Posts: 20
Joined: Thu Jun 30, 2016 4:00 pm
Contact:

Re: Custom mouse cursor in 7.4.x

#4 Post by sonejo »

Thanks a lot for the hints!

This works, of course:

Code: Select all

define config.mouse = {"default":[ ("gui/cursor.png", 1, 1) ] }
But I would like to allow the user to change the cursor in the preferences. I need this, since on Android, they should use the system cursor, and on pc/mac, they can decide if they want a custom cursor or the one of the system.

The old way was like this (I found it on this forum and it worked on 7.3.x):

Code: Select all

init 1 python:
    def change_cursor(type="default"):
        persistent.mouse = type
        if type == "default":
            setattr(config, "mouse", None)
        elif type == "pnc":
            setattr(config, "mouse", {"default" : [("images/cursor_default.png", 30, 30)]})
            
    if not hasattr(persistent, "mouse"):
        change_cursor()
    else:
        change_cursor(persistent.mouse)
And then in the Preferences:

Code: Select all

label _("Cursor Style")
textbutton _("System") action [SetVariable("pnc_cursor", False), Function(change_cursor, type="default")]
textbutton _("Retro") action [SetVariable("pnc_cursor", True), Function(change_cursor, type="pnc")]
This is not working anymore, even it I put

Code: Select all

$ preferences.system_cursor = False
in the init code.

Any hint to get it to work? Or another way to achieve it?

Thank you so much!!

Al the best,

vince

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Custom mouse cursor in 7.4.x

#5 Post by strayerror »

As Andy said in the first reply, you need to use the new preference. You can do so like this:

Code: Select all

# This line is an example, and likely doesn't need to change in your code from what was working prior to 7.4.
define config.mouse = {'default': [('gui/cursor.png', 1, 1)]}

[...]

# The new preference to use is "system cursor" as below.
label _('Cursor Style')
textbutton _('System') action Preference('system cursor', 'enable')
textbutton _('Retro') action Preference('system cursor', 'disable')
There is also Preference('system cursor', 'toggle') if you wish to use the same action to switch between system and custom.

sonejo
Newbie
Posts: 20
Joined: Thu Jun 30, 2016 4:00 pm
Contact:

Re: Custom mouse cursor in 7.4.x

#6 Post by sonejo »

Yeah, that works!

thank you so much!!

All the best,

Vince

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

Re: [SOLVED] Custom mouse cursor in 7.4.x

#7 Post by m_from_space »

Just because I needed to change the mouse cursor on demand and it took a long time figuring it out, here is the very simple solution:

# Define all possible mouse cursors here, while 'default' is the default one.

Code: Select all

define config.mouse = {
    'action':[("images/icons/cursor_action.png",24,24)],
    'back':[("images/icons/cursor_back.png",24,24)],
    'default':[("images/icons/cursor_default.png",12,12)]
}
# Switch to another cursor whenever you feel like it, e.g.
# "default_mouse" is a renpy store variable, see https://www.renpy.org/doc/html/store_va ... ault_mouse

Code: Select all

$ default_mouse = "back"
# Or inside a screen

Code: Select all

screen gameover():
  on "show" action SetVariable("default_mouse", "action")
  on "hide" action SetVariable("default_mouse", "default")
I hope this helps some of you.

Post Reply

Who is online

Users browsing this forum: No registered users