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.

AppGameKit Classic Chat / [SOLVED] Center text to sprite

Author
Message
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 26th Nov 2018 21:30
Hello community,

I have one question about a formula if someone has an idea about it.

I want to achieve the following thing: If I have a random sprite, let's say it looks like a button and I want to add a text to it, what's the formula for CENTERING the text in the middle of that sprite that represents a button? I tried combining getspritex with getspritewidth and gettexttotalwidth, but no good values so far.

Can someone provide me with some info?

Thank you very much!
www.alexmatei.com

The author of this post has marked a post as an answer.

Go to answer

Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 26th Nov 2018 21:46
This may help, but I have not tested it, maybe you need to change some minus to plus

[/url]
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 26th Nov 2018 22:45
That solves my problem indeed! Thank you so much!

One question I have: The text does not stay centered when I scale the sprite (see the attached photos) and on some sprites with different sizes, does not stay centered. Should we change the difference number with a universal value?

Thank you!
www.alexmatei.com

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Nov 2018 08:09 Edited at: 27th Nov 2018 08:34
This post has been marked by the post author as the answer.
you'll have to update the text positioning if the sprite size changes. something like:



...click anywhere to update

edit: hopefully easier to read, now
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 28th Nov 2018 12:10
Thank you both for the information! You helped me a lot and the problem has been solved!
www.alexmatei.com

Login to post a reply

Server time is: 2024-11-23 11:49:07
Your offset time is: 2024-11-23 11:49:07