Hey all,
I've been trying to get RMXP to pause the background music whenever the game window is not focused in the Windows OS, but I'm having trouble getting it to work. Since as of now everything pauses (except for the music) with RMXP when its game window is not focused, I figured something in the Graphics module was causing this pause - though after tinkering with it, I'm not so sure anymore. I edited the Graphics module a bit by making RMXP call my override Graphics update method before the old one so that I could put a check for what the currently active window in Windows is and then check its name against my game window's name - and this works fine.
But the problem is, if I unfocus the game window when its running, the active window check never gets called because the code pauses when the game window isn't focused, despite my editing of the Graphics update method! The only thing I can think of that would cause this is maybe the Ruby interpreter in RMXP is what is pausing when the game window is not focused. If so, is there a solution to this problem? Or is it just a problem with my code?
Here is my modification to the Graphics module:
I know my API calls work because I had it set to print a message if the active window was the game, which it ended up spamming while it was active.
And I've been testing this just in my Scene_Title loop, which just has this bit of code:
So, is there a way to get RMXP to continue running the scripts even while its game window is not focused? Or is there just a flaw in my code?
I'd appreciate any help. Thanks!
I've been trying to get RMXP to pause the background music whenever the game window is not focused in the Windows OS, but I'm having trouble getting it to work. Since as of now everything pauses (except for the music) with RMXP when its game window is not focused, I figured something in the Graphics module was causing this pause - though after tinkering with it, I'm not so sure anymore. I edited the Graphics module a bit by making RMXP call my override Graphics update method before the old one so that I could put a check for what the currently active window in Windows is and then check its name against my game window's name - and this works fine.
But the problem is, if I unfocus the game window when its running, the active window check never gets called because the code pauses when the game window isn't focused, despite my editing of the Graphics update method! The only thing I can think of that would cause this is maybe the Ruby interpreter in RMXP is what is pausing when the game window is not focused. If so, is there a solution to this problem? Or is it just a problem with my code?
Here is my modification to the Graphics module:
Code:
module Graphics
class << self
alias new_update update
def update
hTheActiveWindow = Win32API.new("user32", "GetActiveWindow", [], 'L')
h = hTheActiveWindow.call
getWindowText = Win32API.new("user32","GetWindowText","IPI","L")
name = " "#big enough buffer to support the game's name
getWindowText.call(h, name, 15)
if name.slice(0,7) != "My Game"
p "the focused window is not my game!"
end
#run original Graphics.update method
new_update
end
end
end
And I've been testing this just in my Scene_Title loop, which just has this bit of code:
Code:
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
So, is there a way to get RMXP to continue running the scripts even while its game window is not focused? Or is there just a flaw in my code?
I'd appreciate any help. Thanks!