[SOLVED]Get image position in python?

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
Areski
Newbie
Posts: 7
Joined: Thu May 12, 2016 7:01 am
Contact:

[SOLVED]Get image position in python?

#1 Post by Areski » Sun May 15, 2016 4:24 pm

Hi,

I couldn't find a way to get or set the position of an image in python, since we call them (the images) with their names (strings).

I want to achieve something like this :

Code: Select all

$ Image1.position = Image2.position
Do you think it is possible?
Last edited by Areski on Tue May 17, 2016 1:09 pm, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Get image position in python?

#2 Post by xela » Sun May 15, 2016 5:05 pm

Areski wrote:Do you think it is possible?
It is, but there should be a better way to do whatever it is that you're trying to do.
Like what we're doing? Support us at:
Image

Areski
Newbie
Posts: 7
Joined: Thu May 12, 2016 7:01 am
Contact:

Re: Get image position in python?

#3 Post by Areski » Sun May 15, 2016 5:20 pm

I want to show an image exactly on the same position than an other (while hiding the other image).

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Get image position in python?

#4 Post by xela » Sun May 15, 2016 5:29 pm

Under what conditions? I though if you just showed a new image with the same tag transform properties like position would be carried over? Or not? :D

LoL I haven't used normal VN stuff for so long I can barely remember the basics :(

Edit:

Yeap, I was right:

Code: Select all

image meow = Solid("F00", xysize=(100, 100))
image meow2 = Solid("FFF", xysize=(100, 100))
        
label start:
    show meow at Transform(align=(.5, .5)) as img
    pause
    show meow2 as img
    pause
It is shown at the same position.
Like what we're doing? Support us at:
Image

User avatar
xavimat
Eileen-Class Veteran
Posts: 1433
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: xavimat
Location: Italy
Contact:

Re: Get image position in python?

#5 Post by xavimat » Sun May 15, 2016 7:32 pm

If you don't need the two images showing at the same time, you can use image attributes ( https://www.renpy.org/doc/html/displayi ... l#concepts )

Code: Select all

image meow = Solid("F00", xysize=(100, 100))
image meow new = Solid("FFF", xysize=(100, 100))
       
label start:
    show meow:
        align (.5, .5)
    pause
    show meow new
    pause
The show meow new line hides the first image and shows the new one
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Areski
Newbie
Posts: 7
Joined: Thu May 12, 2016 7:01 am
Contact:

Re: Get image position in python?

#6 Post by Areski » Tue May 17, 2016 11:41 am

xela wrote:Under what conditions? I though if you just showed a new image with the same tag transform properties like position would be carried over? Or not? :D

LoL I haven't used normal VN stuff for so long I can barely remember the basics :(

Edit:

Yeap, I was right:

Code: Select all

image meow = Solid("F00", xysize=(100, 100))
image meow2 = Solid("FFF", xysize=(100, 100))
        
label start:
    show meow at Transform(align=(.5, .5)) as img
    pause
    show meow2 as img
    pause
It is shown at the same position.
Thanks, but the thing is, the image will be moved after being "shown", so I have to get the actual transform (and I really would like to use a python function to show the image)

My dream answer would be something like :

Code: Select all

$ renpy.show('image2', at_list=[Position(xpos=image1.posX,ypos=image1.posY)])
But I can't find a way to get image1.posX in python... (I get an error like "image1 is not defined" anyway at this point)

I'm used to script in C#, so if I'm missing something obvious about renpy and python, tell me :)
Last edited by Areski on Tue May 17, 2016 12:17 pm, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Get image position in python?

#7 Post by xela » Tue May 17, 2016 11:55 am

Areski wrote:

Code: Select all

$ renpy.show('image2', at_list=[Position(xpos=image1.posX,ypos=image1.posY)])
Please note (I already mentioned this before):

Position is outdated and dropped from modern Ren'Py. You will always find some way to get everything just right using modern Transform that does basically the same thing but Position has flaws which you might now be able to get yourself out in the middle of development of your game!

Ok so, we get the the object:

Code: Select all

$ temp = renpy.display.core.displayable_by_tag("master", "image1") # Layer: 'master', Tag: 'image1'
More often than not, you can:

Code: Select all

show image2:
    pos (temp.xpos, temp.ypos)
or your Python equivalent of the same. Problems:

- May not have xpos/ypos properties.
- May have xpos/ypos properties but if you offset or anchored or aligned your "image1", that will not be accounted for.

You should always be able to:

Code: Select all

$ placement = temp.get_placement()
which will return placement data but that is a bit complicated and you'll have to figure it out on your own :( There is also a place function which also needs to be explained...

=======================================>>
So... simplest way is use pos only in your ATL instructions (which you use for movement). Then this:

Code: Select all

$ temp = renpy.display.core.displayable_by_tag("master", "image1") # Layer: 'master', Tag: 'image1'
$ renpy.show('image2', at_list=[Transform(xpos=temp.xpos, ypos=temp.ypos)]
is pretty much guaranteed to work perfectly. This still feels weird to me, sort of: "there should be a better way"...
Like what we're doing? Support us at:
Image

Areski
Newbie
Posts: 7
Joined: Thu May 12, 2016 7:01 am
Contact:

Re: Get image position in python?

#8 Post by Areski » Tue May 17, 2016 12:49 pm

I tried this :
xela wrote:

Code: Select all

$ temp = renpy.display.core.displayable_by_tag("master", "image1") # Layer: 'master', Tag: 'image1'
$ renpy.show('image2', at_list=[Transform(xpos=temp.xpos, ypos=temp.ypos)]

But I got the error :

Code: Select all

AttributeError: 'NoneType' object has no attribute 'xpos'
Are we missing a cast on temp? Is it working for you?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Get image position in python?

#9 Post by xela » Tue May 17, 2016 12:54 pm

Whole code please, image definitions, how you show them and etc. The concept is sound, rest is relative :D
Like what we're doing? Support us at:
Image

Areski
Newbie
Posts: 7
Joined: Thu May 12, 2016 7:01 am
Contact:

Re: Get image position in python?

#10 Post by Areski » Tue May 17, 2016 1:05 pm

It worked! Thanks.

My mistake was to hide 'image1' before declaring "temp". So when using "renpy.display.core.displayable_by_tag()", you have to enter a displayed image.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Get image position in python?

#11 Post by xela » Tue May 17, 2016 1:12 pm

Code: Select all

renpy.display.core.displayable_by_tag()
Get whatever internal system is tracking under that tag atm or None. If you hide the image, it's not tracked any longer.

But you can just work with displayable objects from the get go, there may no be a good reason to use tagging system at all.
Like what we're doing? Support us at:
Image

User avatar
barsunduk
Newbie
Posts: 12
Joined: Fri Jul 18, 2014 1:06 pm
Contact:

Re: Get image position in python?

#12 Post by barsunduk » Sat Dec 08, 2018 10:06 am

xela wrote:
Tue May 17, 2016 1:12 pm

Code: Select all

renpy.display.core.displayable_by_tag()
How to use it with SCREENS?

Code: Select all

init:
    transform walk_to(x1, x2, t=5.0):
        xpos x1
        linear t xpos x2

screen test:
    add "kid" at walk_to(200, 400) id "kid"
    
label start:
    show screen test
    pause
    return
renpy.display.core.displayable_by_tag("screens", "kid") returns None

renpy.get_widget("test", "kid").get_placement()[0] returns None

Post Reply

Who is online

Users browsing this forum: Google [Bot]