How to relocate an image once ADDed to a screen.

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

How to relocate an image once ADDed to a screen.

#1 Post by ISAWHIM »

I have a screen which has several images, added with...

Code: Select all

define ico_you = "ico/you.png"
define ico_her = "ico/her.png"
define ico_him = "ico/him.png"

screen myIcons:
    zorder 10
    fixed:
        add ico_you xpos 100 ypos 300
        add ico_her xpos 100 ypos 500
        add ico_him xpos 100 ypos 700
How can I relocate them, changing the xpos and/or ypos? I "defined" them, in hopes that I could alter the attributes that way, but I am not having any luck getting them to move. Define is apparently just a "name" of the "path", not the actual image, located at the path.

I need them to move over to another location, to indicate the rooms they are in. (Not a transition, just a blunt relocation to new X,Y positions.)

Is there another way I should do this? I put them on a screen, so I can hide them when the dialogue displays and only show them when needed. There are many more icons and actual positions. This is simplified for this example only.

NOTE: Using this... will not work, giving errors... though it says ADD accepts images and displayables...

Code: Select all

image ico_you = "ico/you.png"

screen myIcons:
    zorder 10
    fixed:
        add ico_you xpos 100 ypos 300
NameError: name "ico_you" is not defined

https://www.renpy.org/doc/html/screens.html#add
Add
Adds an image or other displayable to the screen.
https://www.renpy.org/doc/html/displayables.html#images

Can I do this something like how the dialogue-box ADDs an image...
add SideImage()
but, obviously... My code instead. Because, SideImage() is a built-in for RenPy, I think.
add MyImage()

I assume that I might be able to create a function that returns an image, with properties set, as the MyImage()... Not sure how to setup that, within a function, exactly.

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: How to relocate an image once ADDed to a screen.

#2 Post by ISAWHIM »

I opted for python code to hammer the images onto a custom layer instead.

Took a while to figure-out everything I needed, but there didn't seem to be a native RenPy solution, that I could find. Lots of info in the help-files, but no actual examples to show you where any of the proposed info actually goes. Leaves me guessing again, and 99% of the guesses seem to be wrong.

I am using a python function to "update", X and Y positions, using renpy.show() and Transform(). The layer being hidden with renpy.hide().

Code: Select all

image ico_you = "ico/you.png"

init python:
    config.layers = [ 'master', 'transient', 'screens', 'myLayer', 'overlay' ]

    YOU = "out"
    LOC = {"home":[100,300], "out":[100,500]}

    def funcMoveMe():
        global YOU
        global LOC
        if YOU == "":
            renpy.hide("ico_you", layer="myLayer")
            # Hide the whole layer...
            # renpy.scene(layer="myLayer")
        else:
            z = Transform(xpos=LOC[YOU][0], ypos=LOC[YOU][1])
            renpy.show("ico_you", at_list=[z], layer="myLayer", zorder=11)
        
label start:
    $YOU = "out"
    $ funcMoveMe()
    "YOU: [YOU]"
    
    $YOU = "home"
    $ funcMoveMe()
    "YOU: [YOU]"
    
    $YOU = ""
    $ funcMoveMe()
    "YOU: Gone"
The value $YOU, is set by clicking on buttons, or by dialogue interactions. The function funcMoveMe(), is fired with the same button-action and manually done, within dialogue, after changing the value of $YOU.

This is not just for one character, but for all characters within the game. They move to the specific location where they can be found. That code is a little more complex.

P.S. ATL code is a nightmare and in severe need of functional code-samples. Depreciated code that it replaces, isn't much better. "Position()" went from being something that was manageable for a "writer", to being something that is co-dependent on being an advanced coder in python. There is no middle-ground on much of this code.

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: How to relocate an image once ADDed to a screen.

#3 Post by RicharDann »

Code: Select all

image ico_you = "ico/you.png"
NameError: name "ico_you" is not defined
Had trouble with this too not long ago. To make it work and still be able to use image statement:

Code: Select all

image ico_you = "ico/you.png"

#And in the screen:
add 'ico_you' xpos 100 ypos 300
Adding the image name between quotes seems to fix the issue for me. Not sure why this isn't in the documentation though, it seems to be a very common problem. As for making them move ATL with arguments would probably be the best way, depending on what you want to do.
The most important step is always the next one.

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: How to relocate an image once ADDed to a screen.

#4 Post by ISAWHIM »

Yea, I opted for ATL.

It is more powerful for manipulation, just not real clear on how to actually do it. Not to mention, applying it is a two-part process.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot]