documentation indexreference manualfunction index

renpy.easy_displayable

Function: renpy.easy_displayable (d, none=False):

This takes an "easy displayable", and returns a Displayable. Easy displayables may be Displayables, or may be strings. If a string, then:

If none is True and d is None, then None is returned. Otherwise, if d is None, an exception is thrown.

Usage

Probably the most practical uses for this function are when you are defining a user interface or making your own custom displayable.

For example, suppose you are making a custom displayable that shows a different image for "healthy", "hurt" and "unconscious" (of course, in practise you can use a ConditionSwitch for this, but for the sake of the example, just roll with it). You could do something like this:

python:

    class CharacterStatus(renpy.Displayable):

        def __init__(self, character, healthy, hurt, unconscious, **properties):
            renpy.Displayable.__init__(self, **properties)

            self.character   = character

            ####################################################################
            #                                                                  #
            #    Here we use renpy.easy_displayable to set the three different #
            # displayables for the three different states.                     #
            #                                                                  #
            #    Note that for the hurt image, you can pass None, and the      #
            # healthy image will be used instead.                              #
            #                                                                  #
            ####################################################################

            self.healthy     = renpy.easy_displayable(healthy)
            self.unconscious = renpy.easy_displayable(unconscious)
            self.hurt        = renpy.easy_displayable(hurt, none=True)

            if self.hurt is None:
                self.hurt = self.healthy

            ####################################################################

        def render(self, width, height, st, at):

            if self.character.health >= 50:
                displayable = self.healthy
            elif self.character.health == 0:
                displayable = self.unconscious
            else:
                displayable = self.hurt

            r = Render(width, height)
            r.blit(renpy.render(displayable, width, height, st, at), (0,0))
            return r

        def visit(self):
            return [ self.healthy, self.hurt, self.unconscious ]

        def per_interact(self):
            renpy.redraw(self, 0)

By doing this you can create one of these custom displayables like this:

image eileen_status = CharacterStatus(
    eileen,
    Animation("eileen_vhappy.png", 1.0, "eileen_happy.png", 1.0),
    None,
    "unconscious_character.png")

Because of renpy.easy_displayable(), you can seamlessly mix an Animation, a static image loaded from a file name, and even "None" - all with very little code within the custom displayable itself. You could even use colours (for example, instead of the unconscious character image, just have a black portrait by using "#000" instead of "unconscious_character.png").


documentation indexreference manualfunction index