change resolution

flashjaysan

New member
Joined
Oct 13, 2021
Messages
4
Hi! I did some forum research but couldn't find something satisfying but I have to admit I'm not really good at finding stuff in forums.
I also searched in the mojo API but to no avail as well. I may be doing it the wrong way.

So I'd like to know how to set the resolution of a game. In BlitzMax it's as easy as calling Graphics(width, height) but with that Mojo class, I thought it would be in its constructor.
Another related question is, if I set the resolution of a game, does it sets the window size in Desktop export and the canvas size in HTML export ? Can I stretch this afterwards (for example for a pixelart like experience in fullscreen) ?
Let's take an example. If I want to set a window/canvas to 640x360, how do I do it and when ?

Code:
Strict

Import mojo


Class MyGame Extends App
    Method OnCreate()
        SetUpdateRate(60)
    End


    Method OnRender()
        Cls(100, 100, 100)
    End
End


Function Main: Int()
    New MyGame()
End
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
856
To set the desktop, use SetDeviceWindow.
For HTML, see the sections on HTML in the App Config Setting.
For 'filtering' on what to do with each target, e.g. desktop/html see the pre-processor section in the Cerberus Language Reference section.

You should also look at the Auto Fit example that comes with Cerberus.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
922
It's valuable to know that In HTML5 you need to set these to change the size, and you cannot
change anything afterwards programmatically as far as I know:

#HTML5_CANVAS_WIDTH=640 'Set the width of the canvas.
#HTML5_CANVAS_HEIGHT=480 'Set the height of the canvas.
#HTML5_CANVAS_RESIZE_MODE=1 '0=locked, 1=stretch, 2=resize
#HTML5_CONSOLE_SHOW=True 'Set it to False to hide the splitter and console DIV in your file.


If you use the above and put any size that matches your screens ratio into the canvas_height & width, and then click fullscreen in the browser after starting it up..you will get a stretched fullscreen. You will get a slight aa effect if you don't set the exact resolution.

You can read the resolution using two sets of commands, the first command reads the windowsize and the other one reads the screensize.
In HTML5 both will give you the same size and that will be 640x480 (default size) or whatever you set using the declarations above.

The two command-sets to get sizes programmatically are :

Code:
' You can read these in OnCreate for instance
Local sw:=DeviceWidth ' screen (same as window in html5)
Local sh:=DeviceHeight

Local ww:=DeviceWindowWidth ' window
Local wh:=DeviceWindowHeight

I think there is a 3:rd commandset that gives you a scaled version I cannot remember what command that was, it was added recently.
 
Last edited:
Top Bottom