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 / Does anyone know the formula AGK uses to recalculates the new width and height if a -1 is used in SetSpriteSize function?

Author
Message
ThrOtherJoJo
12
Years of Service
User Offline
Joined: 24th Mar 2012
Location: California
Posted: 9th May 2014 22:22 Edited at: 10th May 2014 00:12
In the docs, its says that a new width and height will be calculated to maintain the image's aspect ratio so it doesn't look stretched.

So does anyone know the formula AppGameKit uses to recalculates the new width and height if a -1 is used for height?

The reason I'm asking is that I have a sprite that doesn't stay in the same spot depending on the resolution. I'm using the percentage based system. So I thought I would try to write a formula but I'm having issues.

What I thought I could do is find out at what pixel the image is placed at if I gave a value of 30% on the y-axis.
So If I have a resolution of 640x960 and placed the pic at 30% down on the screen that would place the image at approximately 192 pixels down from the top.

Then I thought I could some how figure out where the bottom of the image was, but since I'm using a -1 in the SetSpriteSize function for height, it create a new width and height for that image. The original size of the image is 1024x768.

So since a new height is created, it makes it hard to figure out the formula.

I have attached some pics of the button moving based different resolutions

Joeisms
KG2Entertainment.com

Attachments

Login to view attachments
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 9th May 2014 23:59 Edited at: 10th May 2014 00:00
I believe it probably just uses the aspect ratio:



Not tested, it may be the other way around. I have used similar code in the past to get things looking square or in proportion.

Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 10th May 2014 03:00
After setting the sprite size it is easiest (IMO) to simply call GetSpriteHeight()

ThrOtherJoJo
12
Years of Service
User Offline
Joined: 24th Mar 2012
Location: California
Posted: 10th May 2014 04:56 Edited at: 10th May 2014 04:57
@Naphier

Could it be that simple?

Ok. Question.

My original image is 1024x768 and the aspect ratio is set to .75 (768x1024).

When AppGameKit loads the image and the sprite is created, the sprite height is 588 according to agk::GetSpriteHeight().

Then I set the sprite's size by calling SetSizeOfSprite(100.00f,-1.00f);

After that I check the sprite's height again and now it gives a value of 57.421875.

Now am I to assume that this value is the new aspect ratio of the original image?

Joeisms
KG2Entertainment.com
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 10th May 2014 05:15
Yes, it's that easy The manual calculation should do the same for you.
You're using percentage based coordinates so the 57.4 is 57.4% of the display height. I've no idea what the original 588 is. It sounds like it is pixel size, but that's odd. Maybe that's how AppGameKit initializes it then it goes to % system after any sizing command? Not sure. You'd have to test with something smaller to know.

ThrOtherJoJo
12
Years of Service
User Offline
Joined: 24th Mar 2012
Location: California
Posted: 10th May 2014 07:03
Wow. That did it. I can't believe I overlooked that function. Thanks a lot.

Now that I have a better understanding of what AppGameKit does I can freely create the rest of my sprites images instead of relying on virtual buttons.

Not that virtual buttons are cool but, I don't won't all my navigation sprites to be square.

Joeisms
KG2Entertainment.com
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 10th May 2014 07:45

Login to post a reply

Server time is: 2024-04-28 17:13:13
Your offset time is: 2024-04-28 17:13:13