Scripts / Centering A Sprite?

Author
Message
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 30th Dec 2018 17:18 Edited at: 30th Dec 2018 17:26
How would I go about centering a sprite to the absolute center of the screen?
I'm trying to make a sprite that can also rotate but it goes all over the place and i believe this is because i have to also move its offset to the centre but unsure of how to do it exactly?

SetSpriteOffset ( mySprite , 5 , -1 )

With text its great we have a centering option and for prompts but with sprites im having some troubles with this.

Solved! When I set a sprites size and then use half of the width value for the offset, it did the trick.
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 1st Jan 2019 21:31
To revive the question, while i solved my issues with rotating from a centeral point of a sprite, im still curious if there is a simple way to center sprites on the screen?

I'm assuming this would be using a 50,50 positioning and then doing something with the offset so the sprite isnt using its top left anchor point?
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 2nd Jan 2019 19:13
Um, the simple way is "set a sprites size and then use half of the width value for the offset" which you've already proved, haven't you?

You may have to specify boy x and y offsets (and hence x & y size values) to get it exactly centred.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-04-19 23:44:04
Your offset time is: 2024-04-19 23:44:04