Pressing and releasing buttons.
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.
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.
Pressing and releasing buttons.
Is there a way to make a button press action and a button release action?
Re: Pressing and releasing buttons.
Release action is just a normal button action.
There is no simple way to do a button press action. For example, "press" event is used to distinguish touch and long touch that correspond to normal action and alternate action.
Here is rough example how you can create such functionality using CDD:
Code: Select all
init python:
import pygame
class OnPressAction(renpy.Displayable):
def __init__(self, action, button_dispalyable, **kwargs):
super().__init__(**kwargs)
self.action = action
self.width = 0
self.height = 0
self.child = button_dispalyable
def render(self, width, height, st, at):
t = Transform(child=self.child, alpha=0)
cr = renpy.render(t, width, height, st, at)
self.width, self.height = cr.get_size()
r = renpy.Render(self.width, self.height)
r.blit(cr, (0, 0))
return r
def event(self, ev, x, y, st):
if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
if x > 0 and x < self.width and y > 0 and y < self.height:
return renpy.run(self.action)
Code: Select all
screen test:
default var = 0
label "[var]" xalign 0.5 yalign 0.0
fixed:
xfit True yfit True
xalign 0.5 yalign 0.5
imagebutton:
idle Solid("#f00", xysize=(200,200))
hover Solid("#ff0", xysize=(200,200))
action SetScreenVariable("var", var + 10)
add OnPressAction(SetScreenVariable("var", var + 1), Solid("#f00", xysize=(200,200)))
Code: Select all
label start:
call screen test
Code: Select all
transform some_transform:
zoom 2.0
screen test:
default var = 0
label "[var]" xalign 0.5 yalign 0.0
fixed:
at some_transform
...
Who is online
Users browsing this forum: Bing [Bot]