Getting the Device Screen Size

Monkey Targets Forums/iOS/Getting the Device Screen Size

APC(Posted 2013) [#1]
I am converting one of my apps to Monkey.
I need to determine the device screen size so I can adjust the graphics to the correct size and resolution.(iPhone, iPhone Retina, iPad, Mini and so on.

Is the code below correct to do that:
SCREEN_WIDTH = DeviceWidth()
SCREEN_HEIGHT = DeviceHeight()



rIKmAN(Posted 2013) [#2]
DeviceWidth() / DeviceHeight() return the current resolution yes.

You might want to use autofit by DruggedBunny which takes away all the hassle of dealing with resizing the graphics and input co-ordinates for Touch commands etc, it really is a godsend.


DiabloV(Posted 2013) [#3]
hello

i try this :

Import mojo

Function Main()
	Print "maurice est la !"
	
Local x:Int = DeviceWidth()

Print x

End



but return an error :


Temps �coul� 00:00:02.69
maurice est la !
Monkey Runtime Error : Memory access violation


Shagwana(Posted 2013) [#4]
You need a display before DeviceWidth() will work.

Extend APP and you will see it work.

Import mojo

Function Main()
	Local cGame := New Game_c
End Function


Class Game_c Extends App
    

    Method OnCreate:Int()
        SetUpdateRate 30
        Return 0
    End Method
    
    
    Method OnUpdate:Int()
        Return 0
    End Method


	Method OnRender:Int()
		Cls
		Print DeviceWidth()
		Return 0
	End Method	

End Class