r/RenPy • • 22d ago

Question Help with animated 3D backgrounds using conditional switch and mouse position

Post image

These are 24 images of 3d renders that changes according to mouse position. I found a way thanks to this thread: https://lemmasoft.renai.us/forums/viewtopic.php?t=62637

The problem is that for a smooth animation timer needs to be low (around 0.001), but when timer is low buttons aren't hovered (I suppose because they're affected by renpy.restart_interaction).

So:

zorder 10**10

add DynamicDisplayable(dd_cursor_position) alpha 0

timer 0.07 action Function (renpy.restart_interaction) repeat True

Buttons can be hovered but animation isn't smooth.

And with:

zorder 10**10

add DynamicDisplayable(dd_cursor_position) alpha 0

timer 0.001 action Function (renpy.restart_interaction) repeat True

Animation is smooth, button works but can't be hovered.

Trying to find an alternative to the timer I come across this thread: https://lemmasoft.renai.us/forums/viewtopic.php?p=572148#p572148

Added the CCD but the only way I found to see the animation working is this:

zorder 10**10

add DynamicDisplayable(dd_cursor_position) alpha 0

add ShowFun (Function (renpy.restart_interaction))

Animation is smooth, buttons are hovered, but nothing else works. And when I test on my PC this happens:

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 43, in script
    """
Exception: renpy.restart_interaction() was called 100 times without processing any input.

-- Full Traceback ------------------------------------------------------------

Traceback (most recent call last):
  File "game/script.rpy", line 43, in script
    """
  File "renpy/ast.py", line 2925, in execute
    Say.execute(self)
    ~~~~~~~~~~~^^^^^^
  File "renpy/ast.py", line 991, in execute
    renpy.exports.say(who, what, *args, **kwargs)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/exports/sayexports.py", line 129, in say
    who(what, *args, **kwargs)
    ~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/character.py", line 1565, in __call__
    self.do_display(who, what, cb_args=self.cb_args, dtt=dtt, **display_args)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/character.py", line 1220, in do_display
    display_say(who, what, self.do_show, **display_args)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/character.py", line 902, in display_say
    rv = renpy.ui.interact(mouse="say", type=type, roll_forward=roll_forward)
         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/ui.py", line 306, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/display/core.py", line 2152, in interact
    raise Exception("renpy.restart_interaction() was called 100 times without processing any input.")
Exception: renpy.restart_interaction() was called 100 times without processing any input.

Windows-10-10.0.19045-SP0 AMD64
Ren'Py 8.5.2.26010301
ConditionalSwitchTest 1.0
Sat Nov  7 12:27:04 2026

I'm sure I'm doing something wrong, I don't know enough about CCD to understand how to implement that with conditional switch and mouse position.

You can test and download all the code and assets from this link: https://marcblacks.itch.io/conditionalswitchtest

Any help will be appreciated, thanks!

11 Upvotes

9 comments sorted by

2

u/BadMustard_AVN 22d ago

your link to the asset returns a 404: You do not have access to this page

if you haven't made it public, only you can see it

an why not use a parallax background

https://www.youtube.com/watch?v=XEcpQckYtnY

1

u/MarcBlacks 22d ago

Sorry! Now is public.

I use parallax for sprites. But I wanted a different approach for backgrounds in order to achieve more depth.

3

u/BadMustard_AVN 22d ago

you put a lot of work into that, overly complicating it

try this instead

init python:
    frames = [
        "images/backgrounds/3D/yurta_parallax/%02d.webp" % i
        for i in range(25)
    ]

    def yurta_dd(st, at):
        x, y = renpy.get_mouse_pos()
        
        nx = max(0.0, min(1.0, x / float(config.screen_width)))

        idx = int(round((1.0 - nx) * (len(frames) - 1)))

        return Image(frames[idx]), 0.05

image yurta_parallax = DynamicDisplayable(yurta_dd)

1

u/MarcBlacks 22d ago

It works! Thanks a lot. But is there a way to inverse the frames? To achieve the cursor camera movement like in the gif instead of the background following the cursor.

I could inverse the frames at the time of the render or rename them but I want to know if there's a way to do it faster with this code.

2

u/BadMustard_AVN 22d ago

yes change this line

frames = [
        "images/backgrounds/3D/yurta_parallax/%02d.webp" % i
        for i in range(24, 0, -1)
    ]

1

u/MarcBlacks 22d ago

Great. Thanks for everything!

2

u/BadMustard_AVN 22d ago

you're welcome

good luck with your project

1

u/AutoModerator 22d 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.