Attaching a GUI-based clock to a wall (SOLVED)

Started by , Sat 09/07/2005 17:20:12

Previous topic - Next topic

JSE

Though I know how to script an in-game clock, I have a problem with positioning it â€" so to speak:

I would like a digital clock to be hanging above a door in one of my game's rooms. As I would like the clock's time display to change dynamically, I have created a GUI for it and tried to position it above the door. The problem is that the room is bigger than the screen and whenever the background moves, the GUI moves with it.

Does anyone know a way of sticking the GUI to the background or fixing it in place?

Rui 'Trovatore' Pires

Unfortunately, I don't believe that is possible... have you considered using overlays instead, or something?

EDIT - Wait, you can try and dynamically reposition the clock every time the viewport changes, using the Viewport's Y coordinate as a reference
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Ashen

(OK, Rui edited while I was working on this, but:)
Wouldn't Overlays have the same problem, since they use screen co-ordinates too?

I think you just need to work out the GUIs position in the room, relative to the Viewport co-ords. (What Rui said.)

E.g., suppose you want the GUI to be at 100, 120, and the viewport starts off at 0,0 (i.e. top left of the image). In the repeatedly_execute for the room, you'd put:
Code: ags

SetGUIPosition (CLOCKGUI, 100 - GetViewportX(), 120 - GetViewportY());


Basicly, you need to work out its position in the room, in screen co-ordintates, roughly:
  guix = roomx - GetViewportX();
  guiy = roomy - GetViewportY();
(Where roomx/roomy are constants.)

And you'll probably have to put in some checks to turn the GUI off if (x,y) is out of bounds (greater than allowed screen co-ords):
Code: ags

// rep_ex
int guix = 400 - GetViewportX();
int guiy = 320 - GetViewportY();  // i.e. CLOCKGUI is at (400,320) *in room co-ords*
if (guix > 319 || guiy > 239) GUIOff (CLOCKGUI); // Turn CLOCKGUI off if it's off screen
else {
  GUIOn(CLOCKGUI);
  SetGUIPosition (CLOCKGUI, 400 - GetViewportX(), 320 - GetViewportY());   
}



You'd probably be better using objects, though. Saves a lot of mucking around.
I know what you're thinking ... Don't think that.

JSE

Hey, this worked! Thanks a lot, both of you! :D

Ashen, your code with SetGUIPosition (or rather GUI.SetPosition in the newest version of AGS) and GetViewportX/Y did the trick.

SMF spam blocked by CleanTalk