Opening the menu on Android/Apple Devices Via Touch Input

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.
Message
Author
crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Opening the menu on Android/Apple Devices Via Touch Input

#1 Post by crimsonnight »

Hey guys, as you know, screen-space on mobile devices is precious, especially when trying to provide a cinematic experience. As such, instead of using the quick menu or an on-screen button, I'd like the menu to be shown (ie the default right-click function) if the player taps and holds anywhere on the screen for 2 seconds; is this possible?
alwaysthesamebluesky.com

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#2 Post by Remix »

Long press (you can set duration and wobble amount (to separate from drag/swipe touches) in config) is governed by the "alternate" button action for Android, so pseudo-code example:

Code: Select all

screen android_overlay():
    # variant "android" # probably better to use renpy.variant test as below
    button:
        alternate ShowMenu( 'main' )

init python:
    if renpy.variant( [ "touch", "android" ] ): config.overlay_screens.append( "android_overlay" )
The configs...

define config.longpress_duration = 0.5
# The amount of time the player must press the screen for for a longpress to be recognized on a touch device.

define config.longpress_radius = 15
# The number of pixels the touch must remain within for a press to be recognized as a longpress.

define config.longpress_vibrate = .1
# The amount of time the device will vibrate for after a longpress.
Frameworks & Scriptlets:

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#3 Post by crimsonnight »

Thanks very much for this @Remix :)

I'd like to get it working before playing around with it but am having an issue doing so.

I guess I add this:

Code: Select all

screen android_overlay():
    # variant "android" # probably better to use renpy.variant test as below
    button:
        alternate ShowMenu( 'main' )
along with the configs to screens.rpy?

And this part:

Code: Select all

init python:
    if renpy.variant( [ "touch", "android" ] ): config.overlay_screens.append( "android_overlay" )
just under the 'start' label (in script.rpy)?

Also, I've tested the code on an actual device, but would it be sufficient just to test it on renpy's android emulator in the future?
alwaysthesamebluesky.com

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#4 Post by Imperf3kt »

The android emulator will not emulate alternate clicks if you use renpy.variant in that manner.
You'll have to continue testing on an actual android device or test without the variant check.
These are only set when running on the actual devices, not when running on in the emulators. These are more intended for use in platform-specific Python. For display layout, use screen variants.
https://www.renpy.org/doc/html/other.ht ... py-version
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#5 Post by Remix »

For the time being (while testing) just throw it all in script.rpy outside of any label block... Once you get it working as wanted, maybe separate the parts and put in other files (personally I'd put both the screen and python: config.overlay bits in screens and the config in options)

Note: You might need to change the ShowMenu call... cannot offhand remember the label name myself, it maybe "_game_menu" or somesuch
Frameworks & Scriptlets:

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#6 Post by crimsonnight »

Ah, that could be the issue! Well according to this page here: https://www.renpy.org/doc/html/keymap.html, the command should be 'game_menu', but when I change the code to:

Code: Select all

button:
        alternate game_menu( 'main' )
I'm getting the following crash when running it on my phone:
https://puu.sh/z8gPf/c3e85628e0.png
https://puu.sh/z8gOk/245016191c.png

Do you have any idea why? :?
alwaysthesamebluesky.com

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#7 Post by DragoonHP »

You want ShowMenu("save")[\b] instead of game_menu

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#8 Post by crimsonnight »

Thanks - I'm no longer getting an error, but the code still doesn't seem to be working :?
alwaysthesamebluesky.com

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#9 Post by DragoonHP »

What are you testing on? Emulator or an actual device?

If you are using the emulator, alternate is triggered by right click on the button

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#10 Post by crimsonnight »

Actual device - although trying to trigger it by right-clicking in the emulator also isn't working :(
alwaysthesamebluesky.com

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#11 Post by DragoonHP »

Can you give it a normal action too and see if that is triggering?

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#12 Post by crimsonnight »

Sorry, I'm a bit of a n00b with this stuff, by normal action, do you mean something like the 'show' command? If so should I remove the 'button:' line too?

Looking over the code again, where is the check for the 'longpress'? What's triggering the button's action at the moment? Do we not need some sort of conditional statement?
alwaysthesamebluesky.com

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#13 Post by DragoonHP »

This:

Code: Select all

screen android_overlay():
    # variant "android" # probably better to use renpy.variant test as below
    button:
        alternate ShowMenu( 'main' )
        action ShowMenu("load")

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#14 Post by crimsonnight »

Still no joy :(
alwaysthesamebluesky.com

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Opening the menu on Android/Apple Devices Via Touch Input

#15 Post by DragoonHP »

No. Try with a simple left click/tap to see if anyything loads.

If nothing loads, that means the screen isn't showing up.

Post Reply

Who is online

Users browsing this forum: Kocker