Questions about resolutions

Monkey Forums/Monkey Programming/Questions about resolutions

Arabia(Posted 2013) [#1]
Found some code by therevills in the forums:

Strict

Import mojo

Const WIDTH:Float = 480
Const HEIGHT:Float = 320

Global SCREEN_WIDTH:Int
Global SCREEN_HEIGHT:Int

Function Main:Int()
	New MyGame
	Return 0
End

Class MyGame Extends App
	Method OnCreate:Int()
		SCREEN_WIDTH = DeviceWidth()
		SCREEN_HEIGHT = DeviceHeight()
		Print SCREEN_WIDTH
		Print SCREEN_HEIGHT
		SetUpdateRate 60
		Return 0
	End
	
	Method OnUpdate:Int()
		Return 0
	End
	
	Method OnRender:Int()
		Cls
		PushMatrix 
			Scale SCREEN_WIDTH/WIDTH, SCREEN_HEIGHT/HEIGHT
			SetColor 255, 0, 0
			DrawRect 0, 0, WIDTH, HEIGHT
		PopMatrix
		Return 0
	End

End


Just wanted to clarify before I get too far (don't want to start the wrong way):

1. If I change

Const WIDTH:Float = 480
Const HEIGHT:Float = 320

to

Const WIDTH:Float = 1024
Const HEIGHT:Float = 768

while I'm writing my code (or anything else for that matter), then this code will correctly scale it to whatever mobile device then runs the code?

and

2. This will sound dumb, but I'm extremely new to mobile devices and even newer to programming for them - are all mobile devices fixed resolution? i.e. can you change the resolution of your mobile device like you can with a standard PC?


And some sort of related questions:

How do I change the canvas size when compiling for HTML5? I'm sure I found it at some stage, but buggered if I can find it now. It defaults on my machine to 640x480

And lastly, I hope this makes sense, are pixels on all devices square? I'm looking at using isometric graphics, and on a PC anyway if you use certain resolutions then it will stretch the image and it won't look isometric using the standard 2 pixels across by 1 pixel for 30 degrees


skape(Posted 2013) [#2]
1. Yes, anything within PushMatrix and PopMatrix will be scaled to the device. In this case WIDTH:HEIGHT would be your "virtual resolution." So, something WIDTH/2 by HEIGHT/2 would take a quarter of the screen space regardless of device resolution. You might want to check out something like DruggedBunny's module: AutoFit though.

2. Yes, in nearly all (all?) current cases if you are limiting "mobile devices" to iOS / Android phones, you typically can't change actual resolution. I say "typically" because there are of course "hackish" ways to do it. But it's not usually something you should worry about as you won't be doing it from your app, unlike on desktop targets (where you might). The exception *might* be some tablets, but I can't speak to that with confidence.

Bonus 1: You need to change it in the <canvas> tag in the actual HTML file.

Bonus 2: There is a difference between actual physical pixels and "virtual pixels." That is, you might scale a virtual pixel to be non-square. On some displays, the graphics card might stretch the resolution to fit the physical pixels in a non uniform way for certain resolutions that are at a different aspect ratio than the hardware display. This would mess with your isometric angles.


Arabia(Posted 2013) [#3]
Thanks, everything you said except the last paragraph made sense - that virtual pixel stuff went way over my head :)


rIKmAN(Posted 2013) [#4]
I would advise using autofit as Unlikely suggested, will save you a whole heap of troubles and is so simple to use you just add 4 lines to your code.


Tibit(Posted 2013) [#5]
2. As a side note, if you tilt a tablet of phone and it is not locked to landscape or portrait then that might be considered a resolution change.


silentshark(Posted 2013) [#6]
I echo rIKmAN's advice. Go and download (and use) autofit. Does what it says on the tin..