Working with Ren’Py:
- Part 1: Downloading and Configuring
- Part 2: Editing and Creating Characters
- Part 3: Scenes and Showing Images
- Part 4: Menus, Labels, and Jumps
- Part 5: Variables and Conditional Statements
- Part 6: Transitions
- Part 7: Building Distributions
Advanced Ren’Py:
- Part 1: Screen Language
- Part 2: Position Style Properties
- Part 3: Animation and Transformation Language
- Part 4: Text and Button
- Part 5: Bar and VBar
- Part 6: Textbutton and Imagebutton
- Part 7: Input, Key, and Mousearea
Customizing Ren’Py:
- Part 1: Editing options.rpy
- Part 2: Editing gui.rpy
- Part 3: Style Inspector and Overriding Styles
- Part 4: Special Screen Names and Overriding Screens
- Part 5: Replacing Default GUI Images
Ren’Py + Python:
- Part 1: Setting and Using Flags
- Part 2: Python Blocks
- Part 3: User-Defined Displayables
- Part 4: User-Defined Statements
- Part 5: Custom Text Tags
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.
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.
Defined as a displayable, new user-generated classes can be added and used with screens to access and show them to players.
GitHub Gist Version:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" | |
return |