Holding the button to implement it?

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
Andredron
Miko-Class Veteran
Posts: 715
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Holding the button to implement it?

#1 Post by Andredron »

Tried to create a function (by type of action,Call...) to hold the button. A friend told how a in Python can for example register the color change of the buttons when you hold.

Code: Select all

label main_menu:
    return
 
define _confirm_quit = False
 
init python:
   
    import pygame
   
    class KeyHold(renpy.Displayable):
   
        def __init__(self,**kwargs):
            super(KeyHold, self).__init__(**kwargs)
           
        def render(self,w,h,st,at):
            global foo
            if foo: r = Solid('#0f0').render(100,100,st,at)
            else:   r = Solid('#f00').render(100,100,st,at)
            renpy.redraw(self,0)
            return r
           
        def event(self, event, x, y, st):
            global foo
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    foo = True
            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_a:
                    foo = False
 
image keycatcher = KeyHold()
                   
label start:
   
    $ foo = False
   
    show keycatcher at truecenter
 
    "press a"
 
    return
and change the variable when the button is held

Code: Select all

label main_menu:
    return
define _confirm_quit = False
 
init python:
   
    import pygame
   
    class Indicator(renpy.Displayable):
        '''
       Used in this example only to track the change of a variable in real time.
       Draws a red box if the global variable foo == False,
       draws a green square, if the global variable foo == True.
       '''
        def render(self,w,h,st,at):
            global foo
            if foo: r = Solid('#0f0').render(100,100,st,at)
            else:   r = Solid('#f00').render(100,100,st,at)
            renpy.redraw(self,0)
            return r
 
    class KeyCatcher(renpy.Displayable):
        '''
       When you are on the screen receives events and allows you to respond to them.
       '''
        def render(self,w,h,st,at):
            return Null().render(w,h,st,at)
           
        def event(self, event, x, y, st):
            global foo
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    foo = True
            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_a:
                    foo = False
 
screen bar():
    add KeyCatcher()
    frame:
        align (0.5,0.5)
        vbox:
            add Indicator()
            label "hold a":
                align (0.5,0.5)
                   
label start:
   
    $ foo = False
   
    call screen bar
   
    "end"
 
    return
or tell me if there is already registered function renpy not on the click(action), and the hold buttons(my names function)?

Post Reply

Who is online

Users browsing this forum: Google [Bot]