Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

XP Resolution script V0.2 (now has a proper resolution resizer!)

#The original name for this topic was "Simplest resolution script ever?!"

Background:
As ive been playing around with this a little more ive decided to try and make this into a fully operational resolution script for XP (and if you want VX too... after all it has more features than the default!)

Currently this works perfectly for XP but i havnt made any default systems and such for VX (will do that within 48 hours XD)


Features:
*current*
-Resize the screen to 640*480 or 320*240
-Automatically center the window to screen size unless specified otherwise

*in next version*
-Rewritten windows and command classes (already started XD) for use with new resolutions
-Rewritten viewports for new resolutions (almost done... just aliasing)
-Rewritten Bitmap class for auto size reduction (hopefully)

Script:
simply add this in a new script above main and use the call script commands (written below the script) to use it's features! (sorry for lack of commenting but i just dont do that while working... someone else can do that for me if they REAAAALLLY want...)

Code:
module Resolution
  GetWindowPlacement = Win32API.new('user32','GetWindowPlacement',['l','p'],'l')
  GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics',['i'],'i')
  MoveWindow = Win32API.new('user32','MoveWindow',['l','i','i','i','i','l'],'l')
  FindWindowEx = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i')
  def self.windowloc(window)
    string = ' ' * 44
    Resolution::GetWindowPlacement.call(window,string)
    windowdetails = string.unpack('L11')
    result = []
    result.push((windowdetails[9] - windowdetails[7]))
    result.push((windowdetails[10] - windowdetails[8]))
    result.push(windowdetails[7])
    result.push(windowdetails[8])
    return result
  end
end
class Screen
  def self.center
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    width,height = Resolution.windowloc(window)[0..1]
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,(screenwidth - width) / 2,(screenheight - height) / 2,width,height,1)
  end
  def self.resize2(width,height,x,y)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,x,y,width,height,1)
  end
  def self.move(x,y)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    width,height = Resolution.windowloc(window)[0..1]
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,x,y,width,height,1)
  end
  def self.resize(width,height,center = true)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    if center
      Resolution::MoveWindow.call(window,(screenwidth - width) / 2,(screenheight - height) / 2,width,height,1)
    else
      x,y = Resolution.windowloc(window)[2..3]
      Resolution::MoveWindow.call(window,x,y,width,height,1)
    end
  end
  def self.half(center = true)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    if center
      Resolution::MoveWindow.call(window,(screenwidth - 326) / 2,(screenheight - 272) / 2,326,272,1) 
    else
      x,y = Resolution.windowloc(window)[2..3]
      Resolution::MoveWindow.call(window,x,y,326,272,1)
    end
  end
  def self.default
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,(screenwidth - 646) / 2,(screenheight / 2) - 273,646,512,1)
  end
end


Use:
To return the screen back to default position
Code:
Screen.default

To manually change the screen size
Code:
Screen.resize(width,height)

To manually change the screen size (without centering the window)
Code:
Screen.resize(width,height,false)

To manually change the screen size and choose your own x and y location
Code:
Screen.resize2(width,height,x,y)

To center the current window
Code:
Screen.center

To half the window size (game size = 320*240)
Code:
Screen.half

To half the window size (game size = 320*240)(without centering the window)
Code:
Screen.half(false)

To choose your own window location using the current size
Code:
Screen.move(x,y)


All of the above calling methods can be used in normal and evented call script systems.



Final note:
I hope you like this new addition and i promise that i'll keep improving it to make it the best resolution script EVARGH!
 
Very nice, I like it.
One thing you've put Height and Width the wrong way round, you've might wana swap them so you don't confuse people.
 
I just tested it out, but there is a syntax error for: "  MoveWindow.call(window,X pos,Y pos,HEIGHT,WIDTH,1)". Though if we will be able to change resolution without compatibility or changing maps I will love this script!
 
Sorry, I did read the above posts it's just I didn't understand them. I was wondering if someone could please make an addition to this in which it resizes the viewport such as in the Full Screen feature of the default scripts and make it so when you change back from Full Screen it stops it from going back to the default resolution.
 
This looked interesting to me, I like simple.

Anyway, I did some playing and came up with this:
Code:
  # Begin Screen Resolution
  WIDTH = 1024
  HEIGHT = 768
  
  SM_CXSCREEN, SM_CYSCREEN = 0, 1 
  GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
    screenwidth = GetSystemMetrics.call(SM_CXSCREEN)
    screenheight = GetSystemMetrics.call(SM_CYSCREEN) 
  FindWindowEx = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i')
    window = FindWindowEx.call(0,0,"RGSS Player",0)
  MoveWindow = Win32API.new('user32','MoveWindow',['l','i','i','i','i','l'],'l')
    x = (screenwidth - WIDTH) / 2
    y = (screenheight - HEIGHT) / 2
    MoveWindow.call(window,x,y,WIDTH,HEIGHT,1)
  # End Screen Resolution

All you do is specify a height and width and it will automatically center the game window.
 
haha this is a nice and simple reso script. though it needs to be re-writed because it lags the game engine too much XD
 
We are still missing the most immportant piece though, the viewport resizing. Can someone please make a viewport resizer and then we can truly have changed resolution?

EDIT: Also nice script Kylock useful because of the automatic centering based on WIDTH and HEIGHT. We also need the when you go to fullscreen it doesn't change the resolution back to default.
 
here... a simpler call and class version of the script:

Code:
class Resolution
  def self.resize(width,height)
    getSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
    moveWindow = Win32API.new('user32','MoveWindow',['l','i','i','i','i','l'],'l')
    findWindowEx = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i')
    window = findWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = getSystemMetrics.call(0)
    screenheight = getSystemMetrics.call(1)
    moveWindow.call(window,(screenwidth - width) / 2,(screenheight - height) / 2,width,height,1) 
  end
end

put that in a new script above main and then when you want to resize the window just use this in a call script command or in the script editor (e.g. after begin in main)

Code:
Resolution.resize(width,height)

with width and height being the pixels in which you want the width and height to be.

Also with the viewport thing im working on rewriting the viewports and plane classes using ruby and C (.dlls)
It may take a long time though :(


*EDIT:
hmm... actually i seem to remember tha poccil's pokemon starter kit was able to resize the plane and viewport without lag... i might have to look at what he did aswell...
 
I still can't understand why people use FindWindowEX API when GetActiveWindow is much better. You just need to do:
Code:
GetActiveWindow = Win32API.new('user32', 'GetActiveWindow', '', 'L')
window = GetActiveWindow.call
Or still simplier:
Code:
window = Win32API.new('user32', 'GetActiveWindow', '', 'L').call
Just better, and it will not fail if the debug frame rate is active or if there are are more than one game opened.
 
because it only works if the window was active when the script was run.
For instance when i made my system menu rewite for the game.exe i made it in RGSS itself. The problem is it doesnt do ANYTHING if the game window isnt active when you start the game, so if you navigate away or something like that as the game starts up... it fails, and that cant be redone.

anyway ive also made a thing that stops two games being run for my games so i dont have that problem ;D
 
Why don't we make it shorter?
Code:
class Resolution
  def self.resize(width,height)
    getSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
    window = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i').call(0,0,"RGSS Player",0)
    Win32API.new('user32','MoveWindow',['l','i','i','i','i','l'],'l').call(window,(getSystemMetrics.call(0) - width) / 2,(getSystemMetrics.call(1) - height) / 2,width,height,1) 
  end
end
or just one line  :tongue:
Code:
class Resolution;def self.resize(width,height);getSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I');window = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i').call(0,0,"RGSS Player",0);Win32API.new('user32','MoveWindow',['l','i','i','i','i','l'],'l').call(window,(getSystemMetrics.call(0) - width) / 2,(getSystemMetrics.call(1) - height) / 2,width,height,1);end;end

And it still works the same way :smile:
 

arev

Sponsor

+++ Rest in peace, Display.dll +++
Nice 'n' clean, although it doesn't work for VX - the content still stretches from 640x480max to window size.
 
I might be wrong, but to make it work with VX you just need to change "RGSS Player" for "RGSS Player 2"
Code:
class Resolution
  def self.resize(width,height)
    getSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
    window = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i').call(0,0,"RGSS Player 2",0)
    Win32API.new('user32','MoveWindow',['l','i','i','i','i','l'],'l').call(window,(getSystemMetrics.call(0) - width) / 2,(getSystemMetrics.call(1) - height) / 2,width,height,1) 
  end
end

I can't test it right now so give me feedbacks!
 
just change it to whatever the .exe manifest is written as. You can use res-hacker to find this out. On the other hand the only use for this would be to move the screen around automatically, after all the VX has its own resolution script (which from inspection i descovered is exactly this but longer, thats why i converted it to RGSS - XP... simple)

*EDIT: By the way should i post more of the API functions ive made or not?
Ive made a new screenshot system and a complete properties dialogue remover (even from the game's system menu XD)
 
well it does, it changes the resolution of the executable's window... on the other hand the tilemap class is hidden and thats within the game scripts. If you want that rewritten completely (as sephirothspawns doesnt load everything correctly and its more laggy) then give me some time... im working on it... also ive already rewritten the window, base, selectable and command classes to allow the new resolution and the viewports have been changed too. What im hoping to do is make the game zoom the entire tilemap out by 50% (for 320*240) to start, that way you can use 16*16 graphics by pixelating them up to 32*32 (doubling their size) and then using them, that way they should turn out as a proper looking 16*16 as normal... complicated but as it uses all the default scripts pretty well and hopefully wont lag... its the best system yet (also dont worry about full screen problems as ive removed the ALT + ENTER combo completely from the RGSS102E anyway... also ive removed the F1 from within the game and the dialog box from the RGSS but thats another story XD)


*EDIT* WOOOOOHHHH... major update! It now has loads of new features and ive built it for lag free fun XD
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top