Gestures (Detailed analysis)

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Gestures (Detailed analysis)

#1 Post by Andredron »

If you've ever tried to build a gesture system into a game and looked online for information about it, you realize how terrible its documentation is

https://www.renpy.org/doc/html/gesture.html

It gives very little information and unlike other pages in the documentation - there is no example of use, just obscure theory.


PyTom responded to a user's question about it by saying that gestures are simply matched with keystrokes, and he considers this system a mistake and is not going to improve it in the future. But for us it's not a big deal - the main thing is that it works.

viewtopic.php?p=482127#p482127

Now I'll tell you how I figured it out, did it, customized it and what bugs the presence of gestures causes and how to fix them.

Initialization - let's write one of them in options.rpy:

Code: Select all

define config.variants = ["phone", "tablet", "touch", "ios", None]

define config.gestures = { "n" : "game_menu",
                           "w" : "help",
                           "e" : "toggle_skip",
                           "s" : "hide_windows"}
                           
init -1700 python:
    _game_menu_screen = "save"
We create gestures by indicating direction using the sides of the world:

North - North, South - South, West - West, East - East. They can be combined via underscores, for example: "n_w".

Well, since the gesture system is just matched with keystrokes, and a keystroke doesn't do what you want - nothing will work, so we have only 4 actions - i.e. we can say 4 screens. I'll tell you what to do about it now, but the gesture system already works after you put in the code and there are already 2 bugs.

Let's say that by swiping down["s"] we want to hide the interface - all is well. Swipe right["e"] to enable skipping - all good. But by swiping up["n"] we want to open not the settings or save menu, but for example - "about the game". Yes, that's how we wanted, but we can only action - game_menu.

The solution - simply in script.rpy or optinons.rpy we write

Code: Select all

init -1700 python:
    _game_menu_screen = "about"
We go further and want to swipe left["w"] to open the dialog history screen. But we won't be able to simply replace the variable. But we don't need to - let's do what real programmers do! We won't do anything and just change the name of the history screen to "help" and everything will work.

Now let's deal with another error - the history screen is called in the main menu. We write about this code and check, and then set the value of the variable "scr_show" at the beginning of the label "start" with the value "True":

screen.rpy

Code: Select all

screen help() :###screen history
    tag menu
    if scr_show:
        #screen history code
    else:
        $ renpy_quit() 
script.rpy

Code: Select all

label start:
    $ scr_show = True
    ############
    jump prolog
Well, there is only one bug left, which is not necessary to fix for those who have 2 different builds - for smartphones and for PC or those who make the game only for one platform. For after we initialized the gesture system - the checkout broke:

if renpy.variant("") — "pc" , "small", "touch" .

And you can fix it by simply replacing this check with a regular variable check.

I leave a link to a project we are experimenting with for the second time and now it has a gesture system built in in addition to the gallery

https://disk.yandex.ru/d/CUJyqjmaczuSkA

Author - https://vk.com/@miosion_pub-sistema-zhestov-v-renpy




viewtopic.php?p=548711- Hide the interface with an upward gesture

viewtopic.php?p=330957 - Crutch number 1

viewtopic.php?p=554242 - Crutch number 2

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]