XP Style Fog

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
XP Style Fog 1.0
Shaz
Introduction
This is a simple port of XP's fog system.

Features
- Add fog via map notes or via a Call Script command
- Change fog tone and opacity via a Call Script command

How to Use
Paste script into a new slot below Materials. All methods are aliased, so this can go below other custom scripts.

Add fog to a map via map notes as follows:

Code:
<fog name hue opacity blend_type zoom speed-x speed-y>
or via a Call Script command:
Code:
Call Script: $game_map.add_fog(name, hue, opacity, blend_type, zoom, speed_x, speed_y)
Change fog via a Call Script command:
Code:
Call Script: $game_map.start_fog_tone_change(red, green, blue, gray, duration)Call Script: $game_map.start_fog_opacity_change(opacity, duration)
Script
Code:
#============================================================================# XP Style Fog# v1.0 by Shaz#----------------------------------------------------------------------------# This is a simple port of XP's fog system.#----------------------------------------------------------------------------# To Install:# Copy and paste into a new script slot in Materials.  This script aliases# existing methods, so can go below all other custom scripts.#----------------------------------------------------------------------------# To Use:# Create a Fogs folder inside your game's Graphics folder, and paste your# fog png files there## There are two ways of adding fog to a map:# 1. Set it in map notes - fog will be loaded when the map is loaded (all values #    must be present)#    <fog name hue opacity blend_type zoom speed-x speed-y># 2. via a Call Script command - fog will be added when the command is run#    Call Script: $game_map.add_fog(name, hue, opacity, blend_type, zoom, #      speed_x, speed_y)## Use the following two commands to make changes to fog# Call Script: $game_map.start_fog_tone_change(red, green, blue, gray, duration)# Call Script: $game_map.start_fog_opacity_change(opacity, duration)## You can also modify the $game_map fog attr_accessors individually via # Call Script commands.#----------------------------------------------------------------------------# Terms:# Use in free or commercial games# Credit Shaz#============================================================================module Cache  #--------------------------------------------------------------------------  # * Get Fog  #--------------------------------------------------------------------------  def self.fog(filename, hue)    load_bitmap("Graphics/Fogs/", filename, hue)  endendclass Game_Map  #--------------------------------------------------------------------------  # * Public Instance Variables  #--------------------------------------------------------------------------  attr_accessor :fog_name                 # fog file name  attr_accessor :fog_hue                  # fog hue  attr_accessor :fog_opacity              # fog opacity level  attr_accessor :fog_blend_type           # fog blending method  attr_accessor :fog_zoom                 # fog zoom rate  attr_accessor :fog_sx                   # fog sx  attr_accessor :fog_sy                   # fog sy  attr_reader   :fog_ox                   # fog x-coordinate starting point  attr_reader   :fog_oy                   # fog y-coordinate starting point  attr_reader   :fog_tone                 # fog color tone  #--------------------------------------------------------------------------  # * Setup  #--------------------------------------------------------------------------  alias shaz_fog_game_map_setup setup  def setup(map_id)    shaz_fog_game_map_setup(map_id)    setup_fog    setup_notes  end  #--------------------------------------------------------------------------  # * Setup Notes  #--------------------------------------------------------------------------  def setup_notes    @map.note.split(/[\r\n+]/).each do |line|      case line      when /<fog\s*(\w+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)>/i        @fog_name = $1        @fog_hue = $2.to_i        @fog_opacity = $3.to_i        @fog_blend_type = $4.to_i # 0-normal, 1-add, 2-sub        @fog_zoom = $5.to_i        @fog_sx = $6.to_i        @fog_sy = $7.to_i      end    end  end  #--------------------------------------------------------------------------  # * Setup Fog  #--------------------------------------------------------------------------  def setup_fog    @fog_name = ""    @fog_hue = 0    @fog_opacity = 0    @fog_blend_type = 0    @fog_zoom = 0    @fog_sx = 0    @fog_sy = 0    @fog_ox = 0    @fog_oy = 0    @fog_tone = Tone.new(0, 0, 0, 0)    @fog_tone_target = Tone.new(0, 0, 0, 0)    @fog_tone_duration = 0    @fog_opacity_duration = 0    @fog_opacity_target = 0  end  #--------------------------------------------------------------------------  # * Add Fog  #--------------------------------------------------------------------------  def add_fog(name, hue = 90, opacity = 64, blend_type = 0, zoom = 200, sx = 0, sy = 0)    @fog_name = name    @fog_hue = hue    @fog_opacity = opacity    @fog_blend_type = blend_type    @fog_zoom = zoom    @fog_sx = sx    @fog_sy = sy  end  #--------------------------------------------------------------------------  # * Start Changing Fog Color Tone  #     R, G, B, Gray : tone  #     duration      : time  #--------------------------------------------------------------------------  def start_fog_tone_change(red, green, blue, gray, duration)    @fog_tone_target = Tone.new(red, green, blue, gray)    @fog_tone_duration = duration    if @fog_tone_duration == 0      @fog_tone = @fog_tone_target.clone    end  end  #--------------------------------------------------------------------------  # * Start Changing Fog Opacity Level  #     opacity   : opacity level  #     duration  : time  #--------------------------------------------------------------------------  def start_fog_opacity_change(opacity, duration)    @fog_opacity_target = opacity * 1.0    @fog_opacity_duration = duration    if @fog_opacity_duration == 0      @fog_opacity = @fog_opacity_target    end  end  #--------------------------------------------------------------------------  # * Update Fog  #--------------------------------------------------------------------------  def update_fog    @fog_ox -= @fog_sx / 8.0    @fog_oy -= @fog_sy / 8.0    # Manage change in fog color tone    if @fog_tone_duration >= 1      d = @fog_tone_duration      target = @fog_tone_target      @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d      @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d      @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d      @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d      @fog_tone_duration -= 1    end    # Manage change in fog opacity level    if @fog_opacity_duration >= 1      d = @fog_opacity_duration      @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d      @fog_opacity_duration -= 1    end  end  #--------------------------------------------------------------------------  # * Frame Update  #     main:  Interpreter update flag  #--------------------------------------------------------------------------  alias shaz_fog_game_map_update update  def update(main = false)    shaz_fog_game_map_update(main)    update_fog  endend#==============================================================================# ** Spriteset_Map#------------------------------------------------------------------------------#  This class brings together map screen sprites, tilemaps, etc. It's used# within the Scene_Map class.#==============================================================================class Spriteset_Map  #--------------------------------------------------------------------------  # * Object Initialization  #--------------------------------------------------------------------------  alias shaz_fog_spriteset_map_initialize initialize  def initialize    shaz_fog_spriteset_map_initialize    create_fog    update  end  #--------------------------------------------------------------------------  # * Create Fog  #--------------------------------------------------------------------------  def create_fog    @fog = Plane.new(@viewport1)    @fog.z = 300  end  #--------------------------------------------------------------------------  # * Free  #--------------------------------------------------------------------------  alias shaz_fog_spriteset_map_dispose dispose  def dispose    dispose_fog    shaz_fog_spriteset_map_dispose  end  #--------------------------------------------------------------------------  # * Free Fog  #--------------------------------------------------------------------------  def dispose_fog    @fog.bitmap.dispose if @fog.bitmap    @fog.dispose  end  #--------------------------------------------------------------------------  # * Frame Update  #--------------------------------------------------------------------------  alias shaz_fog_spriteset_map_update update  def update    update_fog    shaz_fog_spriteset_map_update  end  #--------------------------------------------------------------------------  # * Update Fog  #--------------------------------------------------------------------------  def update_fog    return if !@fog    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue      @fog_name = $game_map.fog_name      @fog_hue = $game_map.fog_hue      if @fog.bitmap != nil        @fog.bitmap.dispose        @fog.bitmap = nil      end      if @fog_name != ""        @fog.bitmap = Cache.fog(@fog_name, @fog_hue)      end      Graphics.frame_reset    end        @fog.zoom_x = $game_map.fog_zoom / 100.0    @fog.zoom_y = $game_map.fog_zoom / 100.0    @fog.opacity = $game_map.fog_opacity    @fog.blend_type = $game_map.fog_blend_type    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy    @fog.tone = $game_map.fog_tone  endend
FAQ

Credit and Thanks
- Credit Shaz
- Okay to use in commercial games

Author's Notes
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
Thanks very much for this.  I have a query, rather basic, I'm afraid.  I'm not very experienced with scripts yet.

Does the graphic for this go in Graphics/Pictures or do I need to make a new folder Graphics/Fogs the way XP does  Oops just seen the answer to that

EDIT

I've installed the script, but when I go to open the game I get this error message:

line1: SyntaxError occurred

unexpected tEQQ
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Doesn't seem to be anything wrong with line 1. Are you sure it was saying line 1 of the fog script? That's just a comment - there's nothing there to GIVE a syntax error.


Make sure you copied and pasted the script properly. If the error still occurs, take a screenshot of the error message and post it here (or just write out the FULL and EXACT text of the error message), then open the script in your script editor and take a screenshot of that, making sure the line is visible that the error message refers to.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
Here is the error message

">http://

and here is the screenshot of where the cursor is flashing on the script at line 1 which isn't even text, it's just a line of =======

">http://http://s1323.photobucket.com/user/ksjp17/media/Script_zps3023a86f.png.html



EDIT

I think I see what it is - the #at the beginning of the first line is missing.  I must have missed it when I was copying the script from the opening post..  I'll put it in and see if that helps at all.  I assume it will.

EDIT AGAIN

Yes, that fixed it.  I'm sorry to have troubled you for nothing.  Thanks for taking the time to look at it.
 
Last edited by a moderator:

Ratty524

Veteran
Veteran
Joined
Apr 24, 2012
Messages
607
Reaction score
144
First Language
English
Primarily Uses
RMMV
I don't know why later RPG Makers removed this feature from the defaults. Awesome job so far!
 

ShadowFox

Adventurer
Member
Joined
Mar 13, 2012
Messages
255
Reaction score
10
First Language
English
Primarily Uses
Awesome script. Need to know two things.

Does xp fog pictures work with this script or will the pictures need to be changed.

Is there a way to turn off or remove the fog?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Yes, you can use XP's fog pictures, if you own XP.


To remove fog, just use a Call Script with $game_map.setup_fog as the command, which sets it back to the default (no fog).
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
nice script... foooggggggssss
 

ShadowFox

Adventurer
Member
Joined
Mar 13, 2012
Messages
255
Reaction score
10
First Language
English
Primarily Uses
Awesome. When I buy XP, I'll use the XP fogs. Might take a few days though.

Two more questions though.

Will the XP fog grapgics need editing or will they work if I just import them over?

Can you add more then one fog with this system?

EG adding two or more fogs graphics to make the map look like there is a lot of heat is around such as being in a volcano.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
You can just copy the images over.


This only allows ONE fog to be played at a time. So no, you couldn't do that.
 

Allerka

Veteran
Veteran
Joined
Dec 31, 2012
Messages
289
Reaction score
71
First Language
English
Primarily Uses
I'm trying this out because I made extensive use of the fogs in XP, but I noticed that on larger maps the fog stays locked to the screen. So, if I've got it set to look like clouds drifting above, the clouds seem to follow me, whereas in XP itself they stayed in place across the whole map.. Did I set something wrong, or is there any chance the script can be tweaked to allow fogs that don't move with the player?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
It was basically copied from XP, so SHOULD work the same way.


I have since created a multi-layer fog script that (I think is) a bit easier to use. It works along the same lines, but, obviously, lets you use multiple fogs on a map (and also have more control over where they're placed in relation to tiles, events and players). Maybe give that a go and see if there's any difference.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
Actually that later script also follows the player in the same way. Or at least it does for me.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Alright, I'll check it out. You had the sx and sy set to 0 for both scripts?
 

Kazuki

Veteran
Veteran
Joined
May 22, 2013
Messages
109
Reaction score
7
First Language
English
Primarily Uses
I was wondering why my game keeps crashing whenever I have this Script Call: $game_map.add_fog(Underwater, 0, 64, normal, 0, 2, 0) Underwater is the name of the fog I am using. I placed in a folder entitled "Fogs" as well. I get this error message: underwater game crash.PNG
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I can't be sure if this is the cause in your case, but have you tried putting the fog name in quote marks i.e. your script call would be

$game_map.add_fog("Underwater", 0, 64, normal, 0, 2, 0)

That's what I do for Shaz's other fog script.
 
Last edited by a moderator:

Kazuki

Veteran
Veteran
Joined
May 22, 2013
Messages
109
Reaction score
7
First Language
English
Primarily Uses
I can't be sure if this is the cause in your case, but have you tried putting the fog name in quote marks i.e. your script call would be

$game_map.add_fog("Underwater", 0, 64, normal, 0, 2, 0)

That's what I do for Shaz's other fog script.
I put Underwater in quotation marks but, I get another error message. underwater game crash 2.PNG
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
"normal" isn't an option. Look at the values after the = to see what it's expecting. Normal blending is 0.
 

Kazuki

Veteran
Veteran
Joined
May 22, 2013
Messages
109
Reaction score
7
First Language
English
Primarily Uses
"normal" isn't an option. Look at the values after the = to see what it's expecting. Normal blending is 0.
I set the blending type at 0, the game doesn't crash. However, nothing happens when I applied the script call on a Parellel Processs Event. I also tested the games without any other scripts except this Fog script and I get the same result.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,583
Latest member
write2dgray
Top