How do I use SetDeviceWindow: Void (width:Int, height:Int, flags:Int)

Phil7

Active Member
3rd Party Tool Dev
Joined
Jun 26, 2017
Int means, that you hand the function a number. For example you write SetDeviceWindow(800,600,0)

The word after the function name and the ":" is the kind of value you get as a result from that function. The "void" here just means, that there is no resulting value.

@MikeHart We definitely need a beginners section in the forum. A place where you can ask everything you don't know about Cerberus or programming itself.
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
Ok, if you both feel that it could be useful then I will open a new subforum and move your post over there.
 

przemek

Member
Joined
Sep 18, 2017
Thank you for making that new subforum. Now I'm trying to work out where do I put SetDeviceWindow. I tried to put it to onRender and it end up with screen spasm, which was pretty funny. Now I found where to put it, but now I need to work out how to code butonpressed x = exit. I'll try to find it myself so thankls for setdevicewindow help :)
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
Now I'm trying to work out where do I put SetDeviceWindow.
If you want to set it at the start of your game, then do it inside OnCreate. If you want to switch it during the game, place it inside OnUpdate.
Actually inside OnRender could work too, but don't call it at every frame. I could imagine that it looks weird then.
 

przemek

Member
Joined
Sep 18, 2017
Basically, I am still using time code to test all my things and for some reason none of functions are allowed. I tried before class, inside class, after class, in main functuion, in all onrend, create, update.
 

przemek

Member
Joined
Sep 18, 2017
Code:
Strict

Import mojo



Class CGame Extends App
'timer
    Field lastTick:Int
    Field secs:Int
    Field mins:Int
    Field hrs:Int
    Field dys:Int
 
  'resources
    Field wood:Float
     Field loopedtimeforwood:Int
    
'character
     Field characters_front:Image
     Field characters_back:Image
     Field characters_look_left:Image
     Field characters_look_right:Image
     Field characters_walk_left:Image
     Field characters_walk_right:Image
    Field x:Float
    Field y:Float
     Field character:Image
     Field p1:CGame
    

   
   
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Method OnCreate:Int()
        SetUpdateRate(0)
        lastTick = Millisecs()
        loopedtimeforwood = 0
        wood = 0
       
        SetDeviceWindow(1600,1500,1)
       
   
       
        'character
        character = LoadImage("character_front.png")
        SetUpdateRate 60
        Return 0
       
    End Method
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    Method OnUpdate:Int()
        Local tick:Int = Millisecs()
        If tick>=(lastTick+1000)
            lastTick = tick
            secs += 1
            loopedtimeforwood+=1
        Endif
        If secs > 59 Then
            secs = 0
            mins +=1
            If mins > 59 Then
                mins = 0
                hrs +=1
                If hrs > 23 Then
                    hrs = 0
                    dys += 1
                Endif
            Endif
        Endif
       
       If loopedtimeforwood >= 20
               wood+=1
               If KeyDown (KEY_A) Then wood+=1
           loopedtimeforwood =0
        End
       
       
       If KeyDown (KEY_LEFT) Then x = x - 4
       If KeyDown (KEY_RIGHT) Then x = x + 4
       If KeyDown (KEY_UP) Then y = y-4
       If KeyDown (KEY_DOWN) Then y = y +4
        Return 0
    End Method
    Method OnRender:Int()
       
        Cls 24, 234, 75
        DrawText("Mins: "+secs, 200, 200)
        DrawText("Min: "+mins, 570, 10)
        DrawText("Hour: "+hrs, 510, 10)
        DrawText("Day: "+dys, 460, 10)''''''''''''''''
        DrawText("Wood: "+wood, 100, 100)
       
       
       
        DrawImage character, x, y
        Return 0
       
    End Method
   

   
End Class


Function Main:Int()
    New CGame()
          
   
       Return 0
End Function
By target d you mean device/operating system? if so im doing windows pc
 

Rob Hewitt

Member
Joined
Aug 30, 2017
only bug I could see (apart from that on mine mins went up every second!) was character_front.png is not loaded and leads to a null object, is it being loaded correctly from the <project name>.data directory?

edit: ah, mins doesn't go up every second but the line
DrawText("Mins: "+secs, 200, 200)

makes it look so!
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
By target d you mean device/operating system? if so im doing windows pc
No, I ment which platform do you target when you build your app? SetDeviceWindow works only on the Desktop platform.

So from what I see in your code....

you want to create a fullscreen with a resolution of 1600x1500? :eek: Maybe your monitor supports that, I don't know. Mine doesn't and I never heard of such a fullscreen resolution. I wouldn't be surprised if it doesn't run because of that or looks weird at least.

Well I used Function ExitApp:Int() on all of them and none liked function :/
Please next time post this in a new topic as it isn't related to SetDeviceWindow. I assume that you want to target the desktop platform. To use this command, you need to import another module at the beginning of your code, below or above the Import mojo line.
Import either the OS module or the BRL module. Both have implemented the ExitApp function. But both only work on the Desktop or C++ target.
 

IGOR

New Member
Joined
Dec 8, 2017
Hi.
I place in (Method OnCreate)
SetDeviceWindow(800,600,1)
or
SetDeviceWindow(1024,768,1)
result 640х480 (DeviceWidth x DeviceHeight)

I try DisplayModes ()
I receive the array long in 0
(checked on two different computers and browsers)
Firefox, Opera, Edge
same result (((
 

Phil7

Active Member
3rd Party Tool Dev
Joined
Jun 26, 2017
I guess you are compiling for html target and as far as I know SetDeviceWindow only works on desktop target. If you want to change the size in html you have to edit the CerberusGame.html file in the build folder and change these lines:
var CANVAS_WIDTH=640;
var CANVAS_HEIGHT=480;
not tested recently ;-)
 

IGOR

New Member
Joined
Dec 8, 2017
Thanks! It's a go. I will dig further, but already it to be pleasant to me! (I ask to forgive my English, the translator)
 
Top Bottom