Page 2 of 2

Re: Layered Parallax Code

Posted: Wed Oct 16, 2019 12:19 pm
by ArizaLuca
This code seems to give me problems with LayeredImage characters in that, quite often, this error pops up:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/routes/evan.rpy", line 282, in script
    "Evan maneuvered around the mess with the expertise of someone who had been living in it for a long while."
AttributeError: 'NoneType' object has no attribute 'append'

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

Full traceback:
  File "game/routes/evan.rpy", line 282, in script
    "Evan maneuvered around the mess with the expertise of someone who had been living in it for a long while."
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/ast.py", line 706, in execute
    renpy.exports.say(who, what, *args, **kwargs)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/exports.py", line 1336, in say
    who(what, *args, **kwargs)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/character.py", line 1139, in __call__
    self.do_display(who, what, cb_args=self.cb_args, **display_args)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/character.py", line 842, in do_display
    **display_args)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/character.py", line 591, in display_say
    rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/ui.py", line 295, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/display/core.py", line 2699, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/display/core.py", line 3191, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/display/core.py", line 2091, in draw_screen
    renpy.config.screen_height,
  File "render.pyx", line 546, in renpy.display.render.render_screen
  File "render.pyx", line 247, in renpy.display.render.render
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 154, in renpy.display.render.render
  File "render.pyx", line 247, in renpy.display.render.render
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 154, in renpy.display.render.render
  File "render.pyx", line 247, in renpy.display.render.render
  File "/Users/arizaluca/Desktop/renpy-6.99.13-sdk/renpy/display/layout.py", line 722, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 154, in renpy.display.render.render
  File "render.pyx", line 247, in renpy.display.render.render
  File "accelerator.pyx", line 110, in renpy.display.accelerator.transform_render
  File "render.pyx", line 256, in renpy.display.render.render
AttributeError: 'NoneType' object has no attribute 'append'

Darwin-18.7.0-x86_64-i386-64bit
Ren'Py 7.3.2.320
The Souls in the Seams 1.0
Wed Oct 16 12:16:04 2019
What is up with that?

Re: Layered Parallax Code

Posted: Sat Oct 19, 2019 3:54 pm
by M-77
Hello ArizaLuca, you need to show us the label or at least part of the code this error message came from. Around the line 282 from your script. Maybe you just forgot or deleted some "ยด" or ":" or "()" symbols while working on the code. I am Renpy amateur, so not sure if I can help you with this, but show us some of your code here.

Re: Layered Parallax Code

Posted: Sat Oct 19, 2019 9:38 pm
by ArizaLuca

Code: Select all

show evan blink normal frown at left onlayer front
    show doll at right onlayer front
    show playerghost onlayer front
    $ pmood = 'True'
    $ pbrow = 'True'
    $ pmouth = 'True'
    with dissolve

    "Evan maneuvered around the mess with the expertise of someone who had been living in it for a long while." #### <== Here is where the error occurs.

    "He reached a small table and sat his bag- with the doll- on a big pile of crumpled paper and open books."
    
    show evan blink thoughtful frown onlayer front
    with dissolve
'Evan' is defined as a LayeredImage so the face is normal; playerghost is a LiveComposite image. However this works in cases like this:

Code: Select all

show alister at left onlayer front
    show doll at right onlayer front
    show playerghost onlayer front
    $ pmood = 'True'
    $ pbrow = 'True'
    $ pmouth = 'True'
    with dissolve

    p "..."

    $ pmood = 'halfshut'

    p_thought "This place really hasn't changed a bit..."
    
    $ pbrow = 'sad'
    $ pmouth = 'True'
    
    p_thought "... I wonder if he kept my old room."
Which is in the same game, so I don't know what the issue is.

Re: Layered Parallax Code

Posted: Sun Oct 20, 2019 6:45 am
by M-77
Hmm... I not sure, I not remember all the renpy commands, and have not coded much last months.
But possible you need to add a "n" (for the Narrator, so RenPy can recognize it) before your text "Evan maneuvered around the mess with the expertise of someone who had been living in it for a long while."
And before the "label start:" add "define n = Character("Narrator")". You sure know this but maybe overseen or forgot to do.
It looks like Renpy do not know what the line "Evan maneuvered around the mess with the expertise of someone who had been living in it for a long while." is for.

Re: Layered Parallax Code

Posted: Sun Oct 20, 2019 8:10 am
by isobellesophia
As M-77 said, RenPy cannot recognize the different name define and the character dialogue itself. Which is making RenPy confused. Same for the name of the file image. The correct one must be the same as the charcater and the image like... "Character Maria is for 'm'". And "Image for Maria is for 'm background'" So that RenPy can understand. This is just a advice to help.

The charcater and the narration are still the same, just make the narrator as a character, name it a narrator talker. So that the name can be seen.

Re: Layered Parallax Code

Posted: Mon Sep 18, 2023 9:29 am
by Lubnevsky
So... this thread is pretty old. Ren'Py has since added 3D Stage, which gives us a much easier way to accomplish this. Given that this is the first result for "Ren'Py Parallax" on Google, I thought I'd post the newer method here.

This code is based on the "Ren'Py How To: parallax camera and 'drunken' blur" devlog by Midge on Itch, with some QOL adjustments and the addition of an easing factor by me.

Code: Select all

default persistent.parallax = True #Add a toggle in your settings! Your players will appreciate it.

transform parallax:
    perspective True
    subpixel True
    function moving_camera

# Distances (define more transforms as needed).

transform near:
    truecenter()
    ypos int(config.screen_height*0.528) #shifting the image downwards a bit so the parallax effect doesnt show its cutoff

transform far:
    truecenter()
    zzoom True
    zpos -750

# Setting our images to be near by default, and bgs as far.

define config.default_transform = near
define config.tag_transform = {"bg" : far}

# Moving camera logic

init python:
    def moving_camera(trans, st, at):
        if persistent.parallax:
            x, y = renpy.display.draw.get_mouse_pos()
            
            parallax_factor = 0.055
            target_xoffset = (x - config.screen_width / 2) * parallax_factor
            target_yoffset = (y - config.screen_height / 2) * parallax_factor
            
            easing_factor = 0.055 #closer to 0 = slower, closer to 1 = faster, with 1 being no ease
            trans.xoffset += (target_xoffset - trans.xoffset) * easing_factor
            trans.yoffset += (target_yoffset - trans.yoffset) * easing_factor
        else:
            trans.xoffset = 0
            trans.yoffset = 0
        
        return 0
    
You can just drag and drop this code into your project, wherever you keep custom functions. Since we're applying the parallax-related transforms by default, you don't need to change anything in your script besides adding

Code: Select all

camera at parallax
in the very beginning! :)

Re: Layered Parallax Code

Posted: Thu Feb 29, 2024 3:15 pm
by kallistThe
Hi guys! Thank you for parallax code!
I'm using modified parallax listed here http://renpyfordummies.blogspot.com/201 ... -post.html

But it still has a problem that all parallax layers are above all other content. So my characters hide under parallax images.

Image

I think it will be useful for everyone to modify this code to use it like parallax background with characters above.
Thank you!