Page 1 of 2
Getting the X, Y position of a moving image on the screen
Posted: Thu Dec 09, 2010 7:08 pm
by Glazed Donuts
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?
Re: Getting the X, Y position of a moving image on the scree
Posted: Thu Dec 09, 2010 7:10 pm
by Aleema
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.
Re: Getting the X, Y position of a moving image on the scree
Posted: Thu Dec 09, 2010 7:18 pm
by Glazed Donuts
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?
Re: Getting the X, Y position of a moving image on the scree
Posted: Fri Dec 10, 2010 6:16 pm
by Glazed Donuts
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?
Re: Getting the X, Y position of a moving image on the scree
Posted: Fri Dec 10, 2010 6:27 pm
by PyTom
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.
Re: Getting the X, Y position of a moving image on the scree
Posted: Fri Dec 10, 2010 6:34 pm
by Aleema
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?
Re: Getting the X, Y position of a moving image on the scree
Posted: Fri Dec 10, 2010 10:01 pm
by Glazed Donuts
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.
Re: Getting the X, Y position of a moving image on the scree
Posted: Fri Dec 10, 2010 10:20 pm
by Aleema
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.
Re: Getting the X, Y position of a moving image on the scree
Posted: Fri Dec 10, 2010 11:17 pm
by Glazed Donuts
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?
Re: Getting the X, Y position of a moving image on the scree
Posted: Sat Dec 11, 2010 9:55 am
by Aleema
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.
Re: Getting the X, Y position of a moving image on the scree
Posted: Sat Dec 11, 2010 10:21 am
by Glazed Donuts
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)
Re: Getting the X, Y position of a moving image on the scree
Posted: Sat Dec 11, 2010 10:39 am
by Aleema
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")
Re: Getting the X, Y position of a moving image on the scree
Posted: Sat Dec 11, 2010 10:45 am
by Glazed Donuts
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.
Re: Getting the X, Y position of a moving image on the scree
Posted: Sat Dec 11, 2010 10:49 am
by Aleema
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.
Re: Getting the X, Y position of a moving image on the scree
Posted: Sat Dec 11, 2010 2:06 pm
by Glazed Donuts
THANK YOU!
This is EXACTLY what I needed!
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?