GetPosition on gui element
by Howard Dortch · in Torque Game Engine · 06/19/2006 (8:58 am) · 3 replies
I set up a gui element (bitmap) at some position on the display. resizing is set to relative. when I change display resolutions the object moves to the new relative location as expected.
When I do arrow.getPosition() at the new higher resolution it returns the value set in script as it was created using the lower resolution. How can I get the current display position of a gui element at any resolution?
When I do arrow.getPosition() at the new higher resolution it returns the value set in script as it was created using the lower resolution. How can I get the current display position of a gui element at any resolution?
#2
i suspect that in the object named 'arrow' is not the guiControl you think it is.
try confirming that 'arrow' is the control you think by doing something like arrow.setVisible(0);
i just tried reproing with a button control of my own with horizontal & vertical resizing both set to "relative" and it seemed to work fine:
ps.
since torque's namespace is global,
i try to name GuiControls with a distinctive naming convention to help avoid name collisions.
if you create another guiControl or even a script object anywhere called 'arrow', the one created later will win and the former one(s) will no longer be able to be accessed by name.
so for example, if i'd really been adding a new button to PlayGui,
i'd use a name something like "playgui_button_Okay" or "playgui_button_ViewHelp" or whatever.
07/06/2006 (10:08 am)
Hey Howard -i suspect that in the object named 'arrow' is not the guiControl you think it is.
try confirming that 'arrow' is the control you think by doing something like arrow.setVisible(0);
i just tried reproing with a button control of my own with horizontal & vertical resizing both set to "relative" and it seemed to work fine:
==>echo(myButton.getPosition()); 85 74 (change window size here) ==>echo(myButton.getPosition()); 111 97
ps.
since torque's namespace is global,
i try to name GuiControls with a distinctive naming convention to help avoid name collisions.
if you create another guiControl or even a script object anywhere called 'arrow', the one created later will win and the former one(s) will no longer be able to be accessed by name.
so for example, if i'd really been adding a new button to PlayGui,
i'd use a name something like "playgui_button_Okay" or "playgui_button_ViewHelp" or whatever.
#3
Well it seems the array of positions ALWAYS had the positions of the items as set in the playgui.gui file no matter the resolution.
I thought about it some after you posted and did a test. It seems during the playGui::onWake() call since the gui hasn't got started yet it's only data was from the file. I put a schedule at the end and called a function on a delay to read the positions and all is well.
So my observation is the onWake function is in a state of construction at the time I origionaly called the getPosition() and should have been called after. That is why your method worked because the relative postions had been set. Thanks for the response!
07/06/2006 (1:30 pm)
This was a tutorial and the arrow (unique name) was supposed to point to the gui elements in a sequence. So what I did was get positions of the gui items in an array. During the tutorial the arrow would switch to the next gui element via postion array and sequence or index. Well it seems the array of positions ALWAYS had the positions of the items as set in the playgui.gui file no matter the resolution.
I thought about it some after you posted and did a test. It seems during the playGui::onWake() call since the gui hasn't got started yet it's only data was from the file. I put a schedule at the end and called a function on a delay to read the positions and all is well.
So my observation is the onWake function is in a state of construction at the time I origionaly called the getPosition() and should have been called after. That is why your method worked because the relative postions had been set. Thanks for the response!
Torque 3D Owner Howard Dortch
Default Studio Name