Getting the X, Y position of a moving image on the screen
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.
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.
-
- Regular
- Posts: 121
- Joined: Thu Aug 12, 2010 11:47 am
- Contact:
Getting the X, Y position of a moving image on the screen
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?
- 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
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.
-
- 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
Well this is what I did:
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?
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"
-
- 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
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?
$ 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?
- PyTom
- Ren'Py Creator
- Posts: 16096
- 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
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(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- 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
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?
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?
-
- 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
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.
- 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
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.
-
- 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
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?
- 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
Yes, of course! I guess it's not documented well, but you can add:
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.
Code: Select all
left_bar=Frame("full image", 5, 5), right_bar=Frame("empty image", 5, 5), thumb="image"
-
- 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
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)
- 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
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")
-
- 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
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.
One last question: Can I change the size of the autobar? Right now, it extends all the way across the screen.
- 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
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.
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.
-
- 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
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?
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?
Who is online
Users browsing this forum: No registered users