Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / help to center a word

Author
Message
darzon
7
Years of Service
User Offline
Joined: 23rd Oct 2010
Location: Italy
Posted: 21st Dec 2017 18:12
hi,
I want to center a word on my screen , I have written this code , but the word is no centered on X position of the screen , Y position instead is fixed at 400 pixel.
I want to use a .ttf font ARIAL and I think that the unit of measure of the font is different from pixel

can you help me to correct the code ?


SetWindowSize( 1280, 800, 1 )
SetVirtualResolution( 1280, 800 )
font=LoadFont("Arial.ttf")

parola$="ALL"

tx=Createtext(parola$)
SetTextFont(tx, font)
SetTextSize(tx, 100)

parlen = len(parola$) * 100
pospar = (1280 - parlen ) / 2
SetTextPosition(tx, pospar , 400)

Do
Sync()
loop


smallg
Valued Member
12
Years of Service
Recently Online
Joined: 8th Dec 2005
Location: steam
Posted: 21st Dec 2017 18:23
you want GetTextTotalWidth(parola$) instead of len(parola$)
or use SetTextAlignment(tx,1)
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 21st Dec 2017 18:26
+ Code Snippet

D
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 21st Dec 2017 18:37
ps. - I dont think Arial.ttf will work on iOS/Android cause will have to copy the Arial.ttf from a windows machine and this is copyright material

I would suggest to use the default new style fonts.

Just making you aware
darzon
7
Years of Service
User Offline
Joined: 23rd Oct 2010
Location: Italy
Posted: 21st Dec 2017 20:11
thank you very very much puzzler2018, now its all ok.
about Arial.ttf , the code is for windows and so I don't need to copy Arial.ttf , It remain in windows font folder.
thank you again.

Login to post a reply

Server time is: 2018-01-22 10:19:19
Your offset time is: 2018-01-22 10:19:19