Walking when holding down key

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
Exiscoming
Regular
Posts: 127
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Walking when holding down key

#1 Post by Exiscoming » Sun Nov 01, 2020 2:13 pm

Two questions.

1. I'm trying to add a movement mechanic, but I want the background to move instead of the character.
For this I'm using a screen with a viewport. What do I need to add to make the background move in sync with the amount of dungSteps taken?

2. Right now I've got a BOOL that activates by pressing d on your keyboard. However instead of pressing d and then jumping to a label, is it possible to have a keydown action instead. That looks if a key (in this case the d key) is being held down. And if so, adds +1 to dungSteps every second?

Image

Code: Select all

default dungWalk = False                    				   			 # False is standing still, True is walking
default dungSteps = 0

screen dungeonCave():
    #### Background ####
    viewport:
        xalign 0.0 yalign 0.0 xysize (1920, 1080)
        child_size (1920, 1080)
        
        edgescroll 0, 0
        draggable False
        arrowkeys False
        
        add "dive/pit/bg1.jpg"
        
    #### Character(s) #####
    add "gui/chars/charArtemis.png" xalign 0.35 yalign 0.5 zoom 0.5 xzoom -1
    
    #### How many steps taken #####
    text "[dungSteps]" xalign 0.5 yalign 0.1
    
    #### KEYBINDS ####
    if dungWalk:
        key "d" action SetVariable("dungWalk", False), Jump("dungWalk")
    else:
        key "d" action SetVariable("dungWalk", True), Jump("dungWalk")

label dungWalk:
    while dungWalk and dungSteps < 3000:
        $ dungSteps += 1
        pause 1.0
        
    if dungWalk == False:
        $ renpy.pause(hard='True')

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Walking when holding down key

#2 Post by Per K Grok » Sun Nov 01, 2020 3:01 pm

Exiscoming wrote:
Sun Nov 01, 2020 2:13 pm
Two questions.

1. I'm trying to add a movement mechanic, but I want the background to move instead of the character.
For this I'm using a screen with a viewport. What do I need to add to make the background move in sync with the amount of dungSteps taken?

2. Right now I've got a BOOL that activates by pressing d on your keyboard. However instead of pressing d and then jumping to a label, is it possible to have a keydown action instead. That looks if a key (in this case the d key) is being held down. And if so, adds +1 to dungSteps every second?

Image

Code: Select all

default dungWalk = False                    				   			 # False is standing still, True is walking
default dungSteps = 0

screen dungeonCave():
    #### Background ####
    viewport:
        xalign 0.0 yalign 0.0 xysize (1920, 1080)
        child_size (1920, 1080)
        
        edgescroll 0, 0
        draggable False
        arrowkeys False
        
        add "dive/pit/bg1.jpg"
        
    #### Character(s) #####
    add "gui/chars/charArtemis.png" xalign 0.35 yalign 0.5 zoom 0.5 xzoom -1
    
    #### How many steps taken #####
    text "[dungSteps]" xalign 0.5 yalign 0.1
    
    #### KEYBINDS ####
    if dungWalk:
        key "d" action SetVariable("dungWalk", False), Jump("dungWalk")
    else:
        key "d" action SetVariable("dungWalk", True), Jump("dungWalk")

label dungWalk:
    while dungWalk and dungSteps < 3000:
        $ dungSteps += 1
        pause 1.0
        
    if dungWalk == False:
        $ renpy.pause(hard='True')

I did a bit of experimenting with having a character walk in the game last year. I made this cookbook post that might have something in it you could find useful.

viewtopic.php?f=51&t=53333#p502719

Method 3 in the post would be the one closest to what you are doing here I think.

Exiscoming
Regular
Posts: 127
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Re: Walking when holding down key

#3 Post by Exiscoming » Sun Nov 01, 2020 3:38 pm

Thanks! I'll check it out later tonight.

Post Reply

Who is online

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