How to center objects on screen for hud, ect.

You must understand the Game Editor concepts, before post here.

How to center objects on screen for hud, ect.

Postby Hblade » Mon Jan 26, 2009 5:30 pm

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.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

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

Postby DST » Thu Feb 05, 2009 5:30 pm

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!
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

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

Postby Fuzzy » Thu Feb 05, 2009 8:00 pm

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;
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest