Ren’Py + Python: Part 3: User-Defined Displayables


Working with Ren’Py:

Advanced Ren’Py:

Customizing Ren’Py:

Ren’Py + Python:

Ren’Py is a engine for creating visual novels. It comes with a suite of tools for taking code and transforming it into programs that can be run on Windows, Mac, Linux, and even, with a little more work, mobile platforms like Android and iOS.

Beyond the showing of text and images, Ren’Py can also be extended through introducing new user interface elements, changing its defaults images, and combining Python with its own code to create even more interactive projects.


User-Defined Displayables

Along with using code in different blocks to change variables and define functions, Python can also be used more extensively. Code used within Ren’Py can use its classes and functions to create new objects that can interact with existing ones.

Along with other Displayables, user-created entries can be added. When used in an init python block, new classes can also inherit and use existing Ren’Py classes and properties.

Screenshot 2018-07-25 20.31.41

Note: User-created displayables need a minimum of both constructor and render functions defined to inherit properties from its parent and rules to follow when drawing.

Screenshot 2018-07-25 20.38.46

Defined as a displayable, new user-generated classes can be added and used with screens to access and show them to players.

Screenshot 2018-07-25 20.40.43

GitHub Gist Version:

init python:
class DrawImage(renpy.Displayable):
def __init__(self, child, opaque_distance, transparent_distance, **kwargs):
# Pass additional properties on to the renpy.Displayable
# constructor.
super(DrawImage, self).__init__(**kwargs)
# The child.
self.child = renpy.displayable(child)
# The width and height of us, and our child.
self.width = 0
self.height = 0
def render(self, width, height, st, at):
# Create a transform
t = Transform(child=self.child)
# Create a render from the child.
child_render = renpy.render(t, width, height, st, at)
# Get the size of the child.
self.width, self.height = child_render.get_size()
# Create the render we will return.
render = renpy.Render(self.width, self.height)
# Blit (draw) the child's render to our render.
render.blit(child_render, (0, 0))
# Return the render.
return render
screen draw_image:
add DrawImage("logo.png", 100, 200):
xalign 0.5
yalign 0.5
label start:
show screen draw_image
"Let's draw an image!"

view raw


hosted with ❤ by GitHub