Ren'Py has two systems for creating custom mouse cursors. The first takes advantage of the hardware mouse cursor, while the second uses Ren'Py to draw a displayable as the mouse cursor.
The hardware mouse cursor has the advantages:
And the limitation:
Using Ren'Py to draw a displayable as a cursor inverts these restrictions. While the cursors can be anything Ren'Py can draw, Ren'Py needs to do the drawing. When triple buffering is enabled on a computer, a lag can be present that isn't for the harware cursor.
The hardware cursor is controlled by the config.mouse
variable. This
variable consists of a dictionary, that maps mouse names to a list of frames.
Each frame is a 3-component tuple that contains an image file, and then
X and Y offsets within that image.
For example:
define config.mouse = { }
define config.mouse['default'] = [ ( "gui/arrow.png", 0, 0) ]
define config.mouse['spin' ] = [
( "gui/spin0.png", 7, 7 ),
( "gui/spin1.png", 7, 7 ),
( "gui/spin2.png", 7, 7 ),
( "gui/spin3.png", 7, 7 ),
( "gui/spin4.png", 7, 7 ),
( "gui/spin5.png", 7, 7 ),
( "gui/spin6.png", 7, 7 ),
( "gui/spin7.png", 7, 7 ),
]
When an animation consists of multiple frames, the frames are played back at 20fps. Ren'Py will only change the cursor when the image or offsets change.
A displayable cursor uses the config.mouse_displayable
variable,
and the MouseDisplayable displayable. As an example:
image mouse spin:
"gui/spin0.png"
rotate 0.0
linear 1.0 rotate 360.0
# Pause so image prediction can happen.
pause 1.0
repeat
define config.mouse_displayable = MouseDisplayable(
"gui/arrow.png", 0, 0).add("spin", "mouse spin", 9.9, 9.9)
MouseDisplayable
(cursor, x, y) linkA displayable that wraps a mouse cursor displayable, and causes it to move across the screen when the player moves their mouse.
add
(name, cursor, x, y) linkThis adds a second cursor, that is used when the name mouse is displayed. This returns the MouseDisplayable, so that calls to this method can be chained.
The usual way to use a mouse cursor is to provide the mouse
property,
giving the name of the cursor, to something that can be focused in a
screen. (A button or bar.) For example:
screen test():
textbutton "Mouse Test" action NullAction() mouse "spin"
It's also possible to use default_mouse
to set the mouse cursor
globally:
$ default_mouse = "spin"