123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|446|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Center text different resolutions?

Sat, 12 Jun 2010, 05:59
ShadowIce
Whats up w/ this code?

I can't get this
to stay in the same place
in different resolutions.

even if i use:

center_x
and
center_y.


Sat, 12 Jun 2010, 06:20
Jayenkai
CenterX and CenterY will center the HANDLE of the text, not "on the screen"...

Picturing things physically sometimes helps..


Text 0,0,"Soothers",0,0


Text 0,0,"Soothers",1,1

Note that the text doesn't center itself on the screen. Instead the text moves from being drawn from the top-left, and then across and down, to being wrapped around the location you asked for.

What you need to do is move your X and Y positions to a new position, so that they are at the same relative position on the screen..

Right at the top of your code, you want to define a screen width and height, and keep them with you at all times.
I personally use Globals, others will use Constants..

Global Screen_Width=640
Global Screen_Height=480
Graphics Screen_Width,Screen_Height

(The main difference being, you can change Globals ingame, so if the player changes their resolution, you can follow.. whereas a Const will require a restart of the game.)

Once you have those, deal with percentages, and multiples, rather than actual co-ordinates.
So, if you want something dead center, you'd do...

text Screen_Width/2,Screen_Height/2,"My Text",1,1

or for something near the top right...
text Screen_Width*.9,Screen_Height*.1,"My Text",1,1

etc,etc..

It can get complicated, but that's half the fun of coding

-=-=-
''Load, Next List!''
Sat, 12 Jun 2010, 07:18
CodersRule
I believe there's a Blitz function to get the current screen res?

Just checked- GraphicsHeight and GraphicsWidth.

Sat, 12 Jun 2010, 07:19
ShadowIce
the text is supposed
to move into the
center.

not just appear there
Sat, 12 Jun 2010, 07:22
CodersRule
So make it do that. I'm not going to do all of the work for you.
Sat, 12 Jun 2010, 08:38
bram32
What is info0$? What is tx, ty and nx? What is url_x, url_y, and url$? Where should this function be placed? What resolutions are you trying?
There is one thing, that might not have to do with your question: you shouldn't use LoadFont in a loop. At least: not without FreeFont. That causes memory leaks. On these different resolutions, are you allways using FontSize 25? Because if you reposition the text position, based on the resolution, you might also want to resize it as well.
That said, use:
text px * graphicswidth() / 640, py * graphicsheight() / 480, info0$, true, true
Sat, 12 Jun 2010, 09:14
shroom_monk
bram32 you shouldn't use LoadFont in a loop. At least: not without FreeFont. That causes memory leaks.


Just to clear that up a bit (for ShadowIce), what you're doing is reloading the font into another section of memory every repeat of the loop. This means that as your program runs it quickly uses up all of the available RAM, since copies of the font are being continually loaded. However, since you've only got one variable, the pointers to these bits of memory will be lost (this is the memory leak). FreeFont will unload a font from memory, but really, as bram32 said, LoadFont should be outside any loops.

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Sun, 13 Jun 2010, 19:40
JL235
Even if their wasn't a memory leak (as some languages will fix this for you) it's generally a bad idea to load something multiple times when you don't need to (as loading something once does less work then loading something 60 times a second, every second).

To move it to the centre: make two variables (say x and y) and position them to the starting values. In your loop then add a value to x and y until they have passed half the width and half the height.

When they have passed half width and half height, set x and y to half width and half height (to ensure they are dead centre). Also set a third variable (a flag) to false in order to state that you are no longer moving the text (i.e. you move the text whilst the flag is set to true).

That's the general idea. There are much more complicated ways of doing moving text, but you can work them out once you've built some simple animation.