Gestures on android - Hold gesture? How do I add events?

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
User avatar
GlassHeart
Regular
Posts: 105
Joined: Fri Mar 11, 2011 12:13 pm
Completed: Out of Sight, Summer Found Me, Signed X, Trapped
Projects: Poison Sweet, CryptoHaven
Location: Romania
Contact:

Gestures on android - Hold gesture? How do I add events?

#1 Post by GlassHeart » Fri Sep 16, 2016 5:59 pm

Hello! I've been trying to replace on screen buttons with gestures for my android app, but I am a bit stuck.

init:
$ config.gestures["s"] = "game_menu" #swipe down to open the menu
$ config.gestures["e"] = "skip" #swipe right to skip
$ config.gestures["w"] = "rollback" #swipe left to see previous line
#$ config.gestures["n"] = ? #swipe up to quick save


This is what I have so far. What I want to know is how to add the quick save feature as a swipe up. For the others I've been using the events found in the default keymap here. But there is no quick save there so I am a bit lost. How can I add other events such as qs or auto forward?

Another related question is: are there any other simple gestures that I can use for auto or other functionalities? Such as press and hold, two-finger tap or something similar? I know I can use L-shapes, but I just wanted to know my options.

Thank you very much for reading. Help is greatly apreciated.
Image Image

User avatar
PyTom
Ren'Py Creator
Posts: 15426
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Gestures on android - Hold gesture? How do I add events?

#2 Post by PyTom » Fri Sep 16, 2016 10:18 pm

It's a little indirect. The right way to do this is with a screen that maps keys to actions:

Code: Select all

screen my_keymap:
     key "auto" action Preference("auto-forward", "toggle")
     key "quick_save" action QuickSave()
And then use config.gestures to map those.

Code: Select all

config.gestures['n'] = "quick_save"
config.gestures['n_e_s'] = "auto"
That being said - I'd really reconsider using gestures instead of buttons. They seem very confusing in practice. (The feature only exists so I can access the super-secret progress screen on Android by using a gesture-based version of the Konami code.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
GlassHeart
Regular
Posts: 105
Joined: Fri Mar 11, 2011 12:13 pm
Completed: Out of Sight, Summer Found Me, Signed X, Trapped
Projects: Poison Sweet, CryptoHaven
Location: Romania
Contact:

Re: Gestures on android - Hold gesture? How do I add events?

#3 Post by GlassHeart » Sun Sep 18, 2016 7:44 pm

Thanks for replying, Tom.
I've tried to do as you said but the gesture was not working (all the others are working fine). I attempted to replace gestures with a random key to see if that would make a difference.
Something like this: config.keymap['auto'].append('t')

I got an error which to me sounds like "auto" is not defined properly.

While running game code:
File "game/options.rpy", line 1437, in <module>
config.keymap['auto'].append('t')
KeyError: 'auto'


For anyone wondering, I did manage to fix the problem in another way thanks to Alex by reading this post.

I defined my screen as
screen my_keymap:
key "t" action Preference("auto-forward", "toggle")


Then configured the gesture for swipe down as
config.gestures["s"] = "t"

Then showed the screen at the beginning of the game
show screen my_keymap

This also causes the key "t" to toggle auto, but since I intend to use this on mobile, it shouldn't affect it. It may not be the best solution, but it works well as far as I can tell.
Image Image

Post Reply

Who is online

Users browsing this forum: No registered users