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 / Managing different sized screens

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Mar 2012 13:55
Does anyone have a good method of resizing graphics based on screen size? The issue I see is that an 800-pixel width could be on a 3 inch phone or an 8 inch tablet.

In the simplest example I have a button, and I want it to be big enough to press on a phone (half the screen width), but on a tablet I want it to be a quarter of the screen width so it doesn't look overbearing.

Is this going to have to be a manual option for the user?

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 11th Mar 2012 05:54
How generic does the method have to be? Would you like something can be applied to just about anything (may take some manual tweaking) or something specifically for the button in this case? If it's the latter, I might need a diagram.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Mar 2012 10:09 Edited at: 11th Mar 2012 10:09
You could use "GetDeviceName()" to decide on a larger button size for smaller devices?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Mar 2012 10:27 Edited at: 11th Mar 2012 10:28
Quote: "How generic does the method have to be?"


I'm making apps that can run across multiple devices and platforms, and may involve numerous entities to resize, this kind of idea...



Quote: "You could use "GetDeviceName()" to decide on a larger button size for smaller devices?"


This might be a good starting point. I could suggest a format on first run, based on the known devices, with an option to pick another format.

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Mar 2012 10:55
If you want someone to push that button you'd be better saying "DON'T PUSH THE BUTTON!"

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 11th Mar 2012 11:00
Quote: "I'm making apps that can run across multiple devices and platforms, and may involve numerous entities to resize, this kind of idea..."

Here are the generic formulas that I use (percentage system):

Scaling a sprite to its original size
NormalScale# = 100.0 / GetDeviceWidth()
SetSpriteScale(spr, NormalScale#, NormalScale#)

Scaling to fit on any screen (may result in stretching of the sprite)
// The resolution where the sprite will appear normally e.g 1024x600
BaseWidth# = 1024.0
BaseHeight# = 600.0

ScaleX# = ScreenWidth# / BaseWidth#
ScaleY# = ScreenHeight# / BaseHeight#

// Assuming the above scaling hasn't been performed
SetSpriteScale(spr, ScaleX# * NormalScale#, ScaleY# * NormalScale#)

Example code:

Try out different resolutions via setup.agc file. Note: if you don't like the stretched sprite effect, just scale the sprite using ScaleRatioX# for the x and y parameters. It might not make too much of a difference.

But with the button, it looks like you want it to appear the same size on different resolutions? Try this:
SetSpriteSize(Spr, ImageWidth(GetSpriteImageID(Spr)) / ScreenWidth# * 100, -1)

The sprite should appear the same size regardless of the resolution.

Login to post a reply

Server time is: 2024-11-23 04:52:18
Your offset time is: 2024-11-23 04:52:18