Adam's Lair Forum

game development and casual madness
It is currently 2017/03/24, 10:11

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 2016/12/30, 19:38 
Member
Member

Joined: 2016/10/14, 01:05
Posts: 71
Role: Hobbyist
Thought I would post this here for the interest of others, rather than on the Discord channel.

I want to limit the size of the window that my game runs in to a MINIMUM resolution of 800 by 600. I am only running on a PC.

I have been looking through the Duality forum and I found this from Adam...

viewtopic.php?f=4&t=142

which I THINK basically says you can't dynamically change the window size while the game is running.

Quote:
Well, this part of Duality does not really belong to the "high sophisticated" group of doing stuff. Basically, just change DualityApp.UserData values, call DualityApp.SaveUserData and then restart the program. The current DualityLauncher implementation doesn't provide a builtin way of changing things like screen resolution on the fly. Some room for improvement I guess :)


Is this still correct?

JB


Top
 Profile  
 
PostPosted: 2016/12/30, 19:50 
Member
Member

Joined: 2016/10/14, 01:05
Posts: 71
Role: Hobbyist
Solved.

Solution will be posted soon. Thanks to SirePi and hsnabn for their help.

JB


Top
 Profile  
 
PostPosted: 2017/01/04, 10:04 
Member
Member

Joined: 2016/10/14, 01:05
Posts: 71
Role: Hobbyist
Turns out there was a bug, which Adam and SirePi have fixed.

In order to use this code, you have to update the OpenTK Backend in your project.

Once you've done that from the Package Manager, this code should work.

In your CorePlugin.cs file in your project, you need to override the OnBeforeUpdate method.

This method is called just before the frame is rendered.

You can do it two ways. Here is the longer way of doing it...

Code:
      
        // Override methods here for global logic
        protected override void OnBeforeUpdate()
        {
            base.OnBeforeUpdate();
            if (DualityApp.TargetResolution.X < 750)
            {
                Duality.DualityUserData desiredUserData = new DualityUserData();
                desiredUserData.GfxWidth = 800;
                desiredUserData.GfxHeight = 600;
                desiredUserData.GfxMode = ScreenMode.Window;
                DualityApp.UserData = desiredUserData;
                DualityApp.SaveUserData();
            }
        }

and here is the shorter way
Code:
   // Override methods here for global logic
        protected override void OnBeforeUpdate()
        {
            base.OnBeforeUpdate();
            if (DualityApp.TargetResolution.X < 750)
            {
                DualityApp.ApplyResolution(800, 600, false);
            }
        }

This code resets the window to 800 by 800 if the width of the window decreases to less than 750 pixels wide.

Thanks to Adam, SirePi and hsnabn for their help on this. Any misinformation in this posting is all my fault :)

JB


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group