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 DBPro Corner / Centering a sprite

Author
Message
Magnolia
15
Years of Service
User Offline
Joined: 19th Jan 2009
Location: New Jersey
Posted: 4th Feb 2009 18:40
Hi,

I'm trying to position a button (sprite) in the centre of the screen along the x axis. Is there a command that does this?

Thanks!
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 4th Feb 2009 20:32
That's quite easy to do.
You can get the sprite dimensions by using sprite width and sprite height. Then you scoop up on the screen dimensions in a similar way using screen width and screen height.

To center the sprite, you then simply offset it to half the screen width / height, subtracted by half the sprite width / height.
Like so:


"We know some things about poodles, for example that they are alive, they can bark, they eat meat..."
- Extract from Objects first with Java.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 4th Feb 2009 23:41 Edited at: 4th Feb 2009 23:41
I think something like this would work, using the OFFSET SPRITE command, which offset's the appearence of a sprite but not its actual location:



Login to post a reply

Server time is: 2024-11-24 15:07:09
Your offset time is: 2024-11-24 15:07:09