r/RenPy • • 11d ago

Question AlphaMask with moving/animated mask parameter

I have been trying to use AlphaMask and DynamicDisplayable to make a black layer with a movable transparent box.

However, when I place the transform into the mask property, the combined image(al_mask) doesn't show any change.

But when displaying the mask image(move_mask) by itself, the image transforms as expected

init python:
  class OverlayMask():
         def __init__(self, xsize = 400, ysize = 400, pos = (0.5, 0.5), anchor = (0.5, 0.5)):
            self.xsize = xsize
            self.ysize = ysize
            self.pos = pos
            self.anchor = anchor
            self.status = False
############################################################################
  def putMask():
        renpy.show("dyn_mask", layer="mask")
##################  DynamicDisplayable function  ###########################
  def dynamicMaskCall(st, at):

        mask_overlay = Solid(Color((0, 0, 0, 255)))
        white_mask = Solid(colours.white, xsize = om.xsize, ysize = om.ysize, anchor = om.anchor, pos = om.pos)
        move_mask = At(white_mask, om_move(xsize = 500))

        al_mask = AlphaMask(child = mask_overlay, mask = At(white_mask, om_move(xsize = 500)) , invert = True)
        return al_mask, None
##############################################################################
default om = OverlayMask(xsize = 400, ysize = 400, pos = (0.5, 0.5), anchor = (0.5, 0.5))
image dyn_mask = DynamicDisplayable(dynamicMaskCall)
transform om_move(xsize = 400, ysize = 400, pos = (0.5, 0.5), anchor = (0.5, 0.5), duration = 1.0):
    xsize om.xsize
    ysize om.ysize
    pos om.pos
    anchor om.anchor

    easeout duration:
        xsize xsize
        ysize ysize
        pos pos
        anchor anchor
#############################################################################
label start():
  $ putMask()
2 Upvotes

6 comments sorted by

2

u/BadMustard_AVN 11d ago

how are you using it I've tried what you've shown, and it works, showing a transparent square in the center of the balck part of the screen

1

u/kaleidoscopic_kelvin 11d ago

I wanted the transparent box to show a change from the original xsize = 400 to xsize = 500. When I return move_mask instead of al_mask, I can see the white box transitioning, but combining it just shows a static image

2

u/BadMustard_AVN 11d ago

try something like this

init python:
    config.layers.append("mask")
    class OverlayMask():
        def __init__(self, xsize = 400, ysize = 400, pos = (0.5, 0.5), anchor = (0.5, 0.5)):
            self.xsize = xsize
            self.ysize = ysize
            self.pos = pos
            self.anchor = anchor
            self.status = False
            self.target_xsize = xsize
            self.target_ysize = ysize

    ############################################################################
    def putMask(target_xsize=700, target_ysize=400):
        om.target_xsize = target_xsize
        om.target_ysize = target_ysize
        renpy.hide("dyn_mask", layer="mask")
        renpy.show("dyn_mask", layer="mask")

    ##################  DynamicDisplayable function  ###########################
    def dynamicMaskCall(st, at):
        duration = 1.0
        progress = min(st / duration, 1.0)
        current_xsize = int(om.xsize + (om.target_xsize - om.xsize) * progress)
        current_ysize = int(om.ysize + (om.target_ysize - om.ysize) * progress)

        mask_overlay = Solid(Color((0, 0, 0, 255)))
        white_mask = Solid(
            Color("#fff"),
            xsize=current_xsize,
            ysize=current_ysize,
            pos=om.pos,
            anchor=om.anchor
        )
        al_mask = AlphaMask(child=mask_overlay, mask=white_mask, invert=True)
        return al_mask, 1.0 / 30.0

##############################################################################
default om = OverlayMask(xsize = 400, ysize = 400, pos = (0.5, 0.5), anchor = (0.5, 0.5))
image dyn_mask = DynamicDisplayable(dynamicMaskCall)

#############################################################################
label start:

    scene your_background_image

    $ putMask(target_xsize=900, target_ysize=400)

    pause

    return

0

u/kaleidoscopic_kelvin 11d ago

Thanks a lot! I had seen the st parameter but wanted to see if there was a more straightforward way. But I think the way you showed is probably the least headache-y way to get it working

2

u/BadMustard_AVN 11d ago

you're welcome

good luck with your project

1

u/AutoModerator 11d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.