kellessdee 48 Report post Posted April 4, 2011 I managed to put together a pseudo-blur script for the game map, I wanted it for one of my projects and figured I would share it in case anyone wanted to use it or whatever. Before I post it I just want to set a few things straight: Only the blur script was written by me. CREDITS: Screenshot.dll - Andreas21 Screenshot script - GameGuy (I modified it a bit to work the way I wanted, but I don't have very much knowledge on using Win32Api functions, thankfully GameGuy had a very simple call snapshot script) For this to work you will need the Screenshot.dll, and place it in the game folder SCREENSHOT.DLL > http://www.mediafire.com/?zf41xwmgjzb To use the script, just place this line of code (for example, say in a menu where you wanted a blurred game_map as the background) @some_var_name = Sprite_Blur.new(Blur_intensity [,opacity]) Blur_intensity is the pixel distance that each layer is shifted in each direction Opacity is the opacity of each layer, if left empty it is defaulted to 25. I found that a blur_intensity between 2-3 looked nicest. And I find if you go for higher intensities then it is a good idea to lower the opacity. SCREENSHOT (blur_intensity = 2, opacity = 25) CODE #============================================================================= # * Snapshot script from screenshot.dll, Modified from GAMEGUY's SCRIPT #============================================================================= module Snapshot def self.snap snp = Win32API.new('screenshot.dll', 'Screenshot', %w(l l l l p l l), '') window = Win32API.new('user32', 'FindWindowA', %w(p p), 'l') ini = (Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l') game_name = '\0' * 256 ini.call('Game', 'Title', '', game_name, 255, '.\Game.ini') game_name.delete!('\0') win = window.call('RGSS Player', game_name) count = 0 file_name = 'Graphics/Pictures/temp_screenshot.png' snp.call(0, 0, 640, 480, file_name, win, 2) end end #============================================================================= # ** Sprite_Blur #----------------------------------------------------------------------------- # Creates a temporary snapshot, then mimic a gaussian blur by messing with # opacity and layering the image #============================================================================= class Sprite_Blur #--------------------------------------------------------------------------- # * Object Initialization # blur_val : Pixel distance to layer over to create blur effect # opacity : The opacity of the screenshot layers #--------------------------------------------------------------------------- def initialize(blur_val, opacity=25) # Save temporary screenshot Snapshot.snap() # Create array of screenshots to create layered @sprite = [] # Set bitmap to screenshot bitmap = RPG::Cache.picture('temp_screenshot.png') @sprite[0] = Sprite.new @sprite[0].bitmap = bitmap (1...(8 * blur_val)).each {|i| @sprite.push(Sprite.new) @sprite[i].bitmap = bitmap @sprite[i].opacity = opacity dir = i % 8 case dir when 0 @sprite[i].x -= 1 + (i / 8) @sprite[i].y += 1 + (i / 8) when 1 @sprite[i].y -= 1 + (i / 8) when 2 @sprite[i].x += 1 + (i / 8) @sprite[i].y += 1 + (i / 8) when 3 @sprite[i].x += 1 + (i / 8) when 4 @sprite[i].x += 1 + (i / 8) @sprite[i].y -= 1 + (i / 8) when 5 @sprite[i].y -= 1 + (i / 8) when 6 @sprite[i].y -= 1 + (i / 8) @sprite[i].x -= 1 + (i / 8) when 7 @sprite[i].x -= 1 + (i / 8) end } end #-------------------------------------------------------------------------- # * Dispose Object #-------------------------------------------------------------------------- def dispose # Dispose Screenshots @sprite.each {|sprite| sprite.dispose} # Delete temporary file File.delete('Graphics/Pictures/temp_screenshot.png') end end Hope you guys might be able to get some use out of this as well :) Share this post Link to post Share on other sites
joman195 9 Report post Posted April 4, 2011 This is useful because I was designing a fable-like beer system for my game where the more you drink the blurrier it gets and the harder it gets to walk straight. Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 4, 2011 (edited) oooohh :sweatdrop: I forgot to mention it doesn't do it in real time; it simply saves a snapshot and creates a still blurred image.... Sorry! I was originally trying for a real-time blurring algorithm, but rmxp creates the maps by drawing sprites into separate viewports with different depth values (thus creating 3 layers) and working in a realtime blur would involve layering every sprite like this and altering the opacities. Unfortunately I am not sure how to manipulate direct x through ruby scripts otherwise I could have put in an real gaussian blur algorithm that could be applied over the screen in real time. I will try working out a way to make a new method for the sprite class that will mimic a blur for each sprite, if it doesn't lag like a bitch then I might be able to work out a real-time blurring script. EDIT: I made slight error, the sprites are drawn on, however the tilemap is not drawn as a sprite and there is no built in way to modify the tilemap's opacity. There for the best I could do would be just the event's and player blurred...and that would be really laggy. The best workaround I could see for you would be to create seperate tilesets with a gaussian blur effect added to it so that when the character is drunk you could just switch tilesets and emulate a blur. There may be a way to apply a realtime blur But i believe that is beyond my knowledge anyways sorry man, wish i could help. Edited April 4, 2011 by kellessdee Share this post Link to post Share on other sites
joman195 9 Report post Posted April 4, 2011 NP, thanks for trying. At least I made the player walk funny when drunk, I found a script that when a certain state is added to the party leader the controls constantly change up. Share this post Link to post Share on other sites
rgangsta 43 Report post Posted April 4, 2011 Wow. That's really impressive. I could definitely use this in the future. Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 5, 2011 NP, thanks for trying. At least I made the player walk funny when drunk, I found a script that when a certain state is added to the party leader the controls constantly change up. Hey that's pretty cool! I never thought about the before, creating scripts where you can set states to alter actual gameplay...I will have to keep this in mind. Also I must mention getting drunk in video games is fun, you can drink all you want without spending a cent and without the hangover :alright: And thanks RGangsta I hope you find some use in it! I wanted the script so I could display the menu over a blurred game screen (kinda like a lot of newer games tend to do) and couldn't find any real-time blurring scripts (which I assume is the nature of rmxp, and it seems there isn't much direct ruby/directx support) And unfortunately it isn't quite an "true" blur but it emulates it well enough for me :) I wonder if it's possible to get the screenshot, call somekind of filter to be applied to it then display the screen...I'll have to look into running external software through ruby; Share this post Link to post Share on other sites