Page 1 of 1

How to center objects on screen for hud, ect.

PostPosted: Mon Jan 26, 2009 5:30 pm
by Hblade
This small, simple tutorial will show you how to center align objects that constantly stay at that 1 set point. If you want text at the Top Center of the screen, then you would do this. Screen size: (Your size). We will use 640 X 480.
Code: Select all
xscreen = 640 / 4;
yscreen = 0;

Using the " / 4 " method, it devides the screns X by 4, thus making the center. if you want it at the top left constantly, then you would use 2 instead of 4.
The same thing with yscreen, if youw ant it in the center middle, xscreen = 640 / 4;, and yscreen = 480 / 4;.



Use this on Draw Actor.

Re: How to center objects on screen for hud, ect.

PostPosted: Thu Feb 05, 2009 5:30 pm
by DST
Excellent!

Fuzzy pointed out an optimization that would be useful here; using decimals instead of fractions.

A computer has a much easier time calculating 640*.25 than 640/4.

In this case, however, you don't need to calculate that at all.

640/4 = 160, and always will, so why not just say
xscreen=160;

:D

But your xscreen method makes a lot of sense, I always use actual xy values, and using xscreen would probably save me some headache. Thanks!

Re: How to center objects on screen for hud, ect.

PostPosted: Thu Feb 05, 2009 8:00 pm
by Fuzzy
Looks great you two.

If you want to be flexible, you can do the following in global code.
Code: Select all
#define MIDDLE view.width >> 2
#define CORNER view.width >> 1

then in the HUD actor
Code: Select all
xscreen = MIDDLE;
yscreen = CORNER;