repeat action of 'Key' screen element [solved]

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
Vaendryl
Regular
Posts: 39
Joined: Thu Dec 26, 2013 10:10 pm
Projects: Sunrider
Organization: Love in Space
IRC Nick: vaendryl
Contact:

repeat action of 'Key' screen element [solved]

#1 Post by Vaendryl »

see subject. is this possible? I could probably do something like that by using pygame more closely but I was wondering if there's an easier way to do this that I'm not seeing.

in this case I want to use the WASD keys to scroll a viewport. it works now but you have to tap the button to scroll, which is annoying.
Last edited by Vaendryl on Fri Dec 18, 2015 8:23 pm, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: repeat action of 'Key' screen element while key is held

#2 Post by xela »

Nothing simpler than managing PyGame event comes to mind...
Like what we're doing? Support us at:
Image

User avatar
Vaendryl
Regular
Posts: 39
Joined: Thu Dec 26, 2013 10:10 pm
Projects: Sunrider
Organization: Love in Space
IRC Nick: vaendryl
Contact:

Re: repeat action of 'Key' screen element while key is held

#3 Post by Vaendryl »

alright, I'll have to make that then :) thanks!

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: repeat action of 'Key' screen element [solved]

#4 Post by xela »

Actually there might be, it just never occurred to me to try, Ren'Py seems to have better handling of pygame input through it's own funcs. I just never messed with that :)
Like what we're doing? Support us at:
Image

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: repeat action of 'Key' screen element [solved]

#5 Post by xela »

Something along these lines I guess (prolly needs improvement/corrections):

Code: Select all

screen vp():
    viewport:
        id "vp"
        align (0.5, 0.5)
        child_size (1000, 1000)
        xysize (300, 300)
        draggable True
        has vbox xysize (1000, 1000) box_wrap True spacing 50
        for i in xrange(100): # <== This causes an error under my pre-released channel Ren'Py version, I've reported it. You can use normal viewport setup...
            add Solid("#%06x"%renpy.random.randint(0, 0xFFFFFF), xysize=(100, 50))
            
    $ vpx = renpy.get_widget("vp", "vp").xadjustment if renpy.get_widget("vp", "vp") else None
    if vpx:
        key "repeat_K_RIGHT" action Function(vpx.change, vpx.value + vpx.step)
        key "repeat_K_LEFT" action Function(vpx.change, vpx.value - vpx.step)

# The game starts here.
label start:
    call screen vp
Like what we're doing? Support us at:
Image

User avatar
Vaendryl
Regular
Posts: 39
Joined: Thu Dec 26, 2013 10:10 pm
Projects: Sunrider
Organization: Love in Space
IRC Nick: vaendryl
Contact:

Re: repeat action of 'Key' screen element [solved]

#6 Post by Vaendryl »

that's really interesting :D thanks again!

Post Reply

Who is online

Users browsing this forum: Google [Bot]