Following https://www.renpy.org/doc/html/udd.html i managed to create two custom displayable with updateable text on them.
But how to distinguish what displayable clicked, move them, and detect collision?
displayable code:
Code: Select all
init python:
import math,pygame
class Card(renpy.Displayable):
def __init__(self, child, xsize,ysize, **kwargs):
super(Card, self).__init__(**kwargs)
self.xpos = 0
self.ypos = 0
self.xsize = xsize
self.ysize = ysize
self.x_offset = 0
self.y_offset = 0
self.child = renpy.displayable(child)
self.text = Text("{color=#000}x=%d y=%d"%(self.xpos,self.ypos))
self.dragging = False
def render(self, width, height, st, at):
self.text = Text("{color=#000}x=%d y=%d"%(self.xpos,self.ypos))
child_transform = Transform(child=self.child, xpos=self.xpos, ypos=self.ypos)
text_transform = Transform(child=self.text, xpos=self.xpos, ypos=self.ypos)
child_render = renpy.render(child_transform, self.xsize, self.ysize, st, at)
text_render = renpy.render(text_transform, width, height, st, at)
render = renpy.Render(self.xsize, self.ysize)
render.blit(child_render, (0, 0))
render.blit(text_render, (10,10))
return render
def event(self, ev, x, y, st):
if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
self.dragging = True
elif ev.type == pygame.MOUSEMOTION and self.dragging:
self.xpos = x
self.ypos = y
renpy.redraw(self, 0)
elif ev.type == pygame.MOUSEBUTTONUP and ev.button == 1:
self.dragging = False
self.xpos = x
self.ypos = y
renpy.redraw(self, 0)
return self.child.event(ev, x, y, st)
def visit(self):
return [ self.child, self.text ]
Code: Select all
screen udd:
add Card(Solid((255,255,255,255)),300,300):
xalign 0.75
yalign 0.5
add Card(Solid((255,255,255,255)),300,300):
xalign 0.25
yalign 0.5
label start:
show screen udd
while True:
$ui.interact()
return
Btw, is there more comprehensive guide / cookbook for UDD thing?
Scripting on Ren'Py itself since 2009, but just did not use that functional before and now can't figure out UDD interface and methods usage.