Getting the X, Y position of a moving image on the 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.
Message
Author
Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Getting the X, Y position of a moving image on the screen

#1 Post by Glazed Donuts » Thu Dec 09, 2010 7:08 pm

Is there any way to get the x,y position of an image on the screen that starts from the left then moves to the right? I wanted it to output the position of the image as it's moving across. Is this possible?

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Getting the X, Y position of a moving image on the scree

#2 Post by Aleema » Thu Dec 09, 2010 7:10 pm

How are you moving it? If you move the image based on a variable, meaning, you're telling it to move "x" or "y", where you change x or y somehow through Python, you can output that value since you have full control of it. I don't know if any quick way to do it, where the coordinate comes from the displayable itself.

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Getting the X, Y position of a moving image on the scree

#3 Post by Glazed Donuts » Thu Dec 09, 2010 7:18 pm

Well this is what I did:

Code: Select all

$ imageTestPos = Position(xpos=750, xanchor='left', ypos=550, yanchor='top')
image testImage crop = im.Crop("test.jpg", 0, 0, 50, 50)

show testImage crop onlayer frontlayer at Move((0.0, 550), (1.0, 550), 10.0, xanchor="center", yanchor="center")
#it takes 10 seconds for the image to move across the screen

$imgCoordsX = testImage.x #I wanted to do something like this, but it doesn't work

"The x coordinates are: %(imgCoordsX)d" 
I would assume I would need a loop or something so that it automatically refreshes where the new coordinate is while it's moving, but how do I do this and get the position of the image?

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Getting the X, Y position of a moving image on the scree

#4 Post by Glazed Donuts » Fri Dec 10, 2010 6:16 pm

Alright, I discovered ui.timer, and this might work better than trying to figure out the x/y coordinates, but I'm wondering if this only works for the menus, or can it work for anything?

$ ui.timer(10.0, ui.jumps("menu1_slow"))

So basically, if I wanted to make an image appear or move across the screen for 10 seconds before the user can interact with it, can I use the ui.timer function? or is this only used for menus?

User avatar
PyTom
Ren'Py Creator
Posts: 15443
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Getting the X, Y position of a moving image on the scree

#5 Post by PyTom » Fri Dec 10, 2010 6:27 pm

I think the question is, what do you want the user to be able to do while waiting for the move to finish? It may be that a simple pause is enough.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Getting the X, Y position of a moving image on the scree

#6 Post by Aleema » Fri Dec 10, 2010 6:34 pm

Oh, are you making a mini-game? :)

ui.timer does not only work for menu, and I've used it in mini-games where I time how fast someone clicks something and such. It's useful. I tried using ATL to dynamically change images to imagebuttons at certain times, but I have never gotten it to work. Buttons in ATL are either not supported or glitchy? I dunno, but that would pretty useful for you right now if they did.

Why don't you tell us exactly what you're trying to do, so we can help specifically?

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Getting the X, Y position of a moving image on the scree

#7 Post by Glazed Donuts » Fri Dec 10, 2010 10:01 pm

Well no, I was trying to make a gauge. Basically, the user can click anywhere on the screen and do things while the gauge (which is in the form of an image) is filling up. Then once the gauge is full, then they are able to click on the gauge to advance to a new screen.

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Getting the X, Y position of a moving image on the scree

#8 Post by Aleema » Fri Dec 10, 2010 10:20 pm

I would recommend an autobar for that. It'll just display your variable going up, and you will check the variable, not the displayable, if something needs to happen.

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Getting the X, Y position of a moving image on the scree

#9 Post by Glazed Donuts » Fri Dec 10, 2010 11:17 pm

Thank you! I tried it out and it's great! Can I change the autobar and the gauge into an actual image? Like a picture of a thermometer with a red image/gauge overlay moving up?

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Getting the X, Y position of a moving image on the scree

#10 Post by Aleema » Sat Dec 11, 2010 9:55 am

Yes, of course! I guess it's not documented well, but you can add:

Code: Select all

left_bar=Frame("full image", 5, 5), right_bar=Frame("empty image", 5, 5), thumb="image"
You can also set Thumb to None if you don't want one. The bar will still assume it exists which will create some graphic anomalies for the two extremes (full and empty), but nothing to rage over.

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Getting the X, Y position of a moving image on the scree

#11 Post by Glazed Donuts » Sat Dec 11, 2010 10:21 am

Where do I add that line? I tried adding it to the ui.autobar block, but it's still the default gauge when I run the program. This is what I did:

Code: Select all

init python:
    
    def overlay():
        global old_score
        
        ui.hbox()
        ui.text("Score: ")
        left_bar=Frame("1.png", 5, 5) 
        right_bar=Frame("2.png", 5, 5) 
        thumb="thumb-test.png"    
        ui.autobar(100, old_score, score, 1.0)
        ui.close()

        old_score = score

    config.overlay_functions.append(overlay)

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Getting the X, Y position of a moving image on the scree

#12 Post by Aleema » Sat Dec 11, 2010 10:39 am

Sorry! I meant to the end of your autobar code:

Code: Select all

ui.autobar(100, old_score, score, 1.0, left_bar=Frame("full image", 5, 5), right_bar=Frame("empty image", 5, 5), thumb="image")

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Getting the X, Y position of a moving image on the scree

#13 Post by Glazed Donuts » Sat Dec 11, 2010 10:45 am

Awesome! Thank you so much!! It works great!!

One last question: Can I change the size of the autobar? Right now, it extends all the way across the screen.

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Getting the X, Y position of a moving image on the scree

#14 Post by Aleema » Sat Dec 11, 2010 10:49 am

Yep, you want the values: ", xmaximum=?, ymaximum=?"
Add those to the end just like previous code. Any properties you have for the autobar (including xpos/ypos) need to go in the same place, before the end parenthesis.

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Getting the X, Y position of a moving image on the scree

#15 Post by Glazed Donuts » Sat Dec 11, 2010 2:06 pm

THANK YOU!
This is EXACTLY what I needed! :D

Will I be able to implement a timer for this so while the user is clicking and interacting with other parts of the screen, then the gauge is moving up slowly in the background?

Post Reply

Who is online

Users browsing this forum: Google [Bot]