Use Two Fogs at Once

Double Fogs
Version: 1.0

Introduction

This script let's you use two fogs at once. You control it with the "Script..." event command. Instructions are at the beginning of the script.

Screenshots

Screenshot Spoiler
http://img149.imageshack.us/img149/3361/doublefogsscriptscreenshotnw2.png[/img]


Demo

None.

Script

script Spoiler
#==============================================================================
# ** Double Fogs Script
# By: Daniel3579
#------------------------------------------------------------------------------
# The second fog appears over the first one.
# All of the below commands are done in the "Script..." event command.
# To change the 2nd fog, use $game_map.fog2_name = "filename"
# To change the 2nd fog's hue, use $game_map.fog2_hue = n
# n is equal to 0 through 360.
# To change the 2nd fog's opacity, use $game_map.fog2_opacity = n
# To change the 2nd fog's blend type, use $game_map.fog2_blend_type = n
# n is equal to 0, 1, or 2. 0 is normal.
# To change the 2nd fog's zoom, use $game_map.fog2_zoom = n
# n has to be a decimal, 1.0 is actual size.
# To change the 2nd fog's horizontal scroll, use $game_map.fog2_sx = n
# n is -256 to 256. 0 is still.
# To change the 2nd fog's vertical scroll, use $game_map.fog2_sy = n
# n is -256 to 256. 0 is still.
# To change the 2nd fog's tone, use $game_map.fog2_tone = tone
# tone is Tone.new(red, green, blue[, gray])
# To start a tone change in the 2nd fog, use
# $game_map.start_fog2_tone_change(tone, duration)
# tone is Tone.new(red, green, blue[, gray]) and
# duration is the amount of frames.
# To start an opacity change in the 2nd fog, use
# $game_map.start_fog2_opacity_change(opacity, duration)
# opacity is the opacity you want it to change to, and
# duration is the amount of frames it takes to change.
#==============================================================================

#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :fog2_name                # fog2 file name
  attr_accessor :fog2_hue                 # fog2 hue
  attr_accessor :fog2_opacity             # fog2 opacity level
  attr_accessor :fog2_blend_type          # fog2 blending method
  attr_accessor :fog2_zoom                # fog2 zoom rate
  attr_accessor :fog2_sx                  # fog2 sx
  attr_accessor :fog2_sy                  # fog2 sy
  attr_reader   :fog2_ox                  # fog2 x-coordinate starting point
  attr_reader   :fog2_oy                  # fog2 y-coordinate starting point
  attr_reader   :fog2_tone                # fog2 color tone
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias daniel_fog2_setup setup
  alias daniel_fog2_update update
  #--------------------------------------------------------------------------
  # * Setup
  #     map_id : map ID
  #--------------------------------------------------------------------------
  def setup(map_id)
    daniel_fog2_setup(map_id)
    @fog2_name = ""
    @fog2_hue = 0
    @fog2_opacity = 64
    @fog2_blend_type = 0
    @fog2_zoom = 200
    @fog2_sx = 0
    @fog2_sy = 0
    @fog2_ox = 0
    @fog2_oy = 0
    @fog2_tone = Tone.new(0, 0, 0, 0)
    @fog2_tone_target = Tone.new(0, 0, 0, 0)
    @fog2_tone_duration = 0
    @fog2_opacity_duration = 0
    @fog2_opacity_target = 0
  end
  #--------------------------------------------------------------------------
  # * Start Changing Fog Color Tone
  #     tone     : color tone
  #     duration : time
  #--------------------------------------------------------------------------
  def start_fog2_tone_change(tone, duration)
    @fog2_tone_target = tone.clone
    @fog2_tone_duration = duration
    if @fog2_tone_duration == 0
      @fog2_tone = @fog2_tone_target.clone
    end
  end
  #--------------------------------------------------------------------------
  # * Start Changing Fog Opacity Level
  #     opacity  : opacity level
  #     duration : time
  #--------------------------------------------------------------------------
  def start_fog2_opacity_change(opacity, duration)
    @fog2_opacity_target = opacity * 1.0
    @fog2_opacity_duration = duration
    if @fog2_opacity_duration == 0
      @fog2_opacity = @fog2_opacity_target
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    daniel_fog2_update
    @fog2_ox -= @fog2_sx / 8.0
    @fog2_oy -= @fog2_sy / 8.0
    if @fog2_tone_duration >= 1
      d = @fog2_tone_duration
      target = @fog2_tone_target
      @fog2_tone.red = (@fog2_tone.red * (d - 1) + target.red) / d
      @fog2_tone.green = (@fog2_tone.green * (d - 1) + target.green) / d
      @fog2_tone.blue = (@fog2_tone.blue * (d - 1) + target.blue) / d
      @fog2_tone.gray = (@fog2_tone.gray * (d - 1) + target.gray) / d
      @fog2_tone_duration -= 1
    end
    if @fog2_opacity_duration >= 1
      d = @fog2_opacity_duration
      @fog2_opacity = (@fog2_opacity * (d - 1) + @fog2_opacity_target) / d
      @fog2_opacity_duration -= 1
    end
  end
end

#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
#  This class brings together map screen sprites, tilemaps, etc.
#  It's used within the Scene_Map class.
#==============================================================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias daniel_fog2_dispose dispose
  alias daniel_fog2_update update
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Make viewports
    @viewport1 = Viewport.new(0, 0, 640, 480)
    @viewport2 = Viewport.new(0, 0, 640, 480)
    @viewport3 = Viewport.new(0, 0, 640, 480)
    @viewport2.z = 200
    @viewport3.z = 5000
    # Make tilemap
    @tilemap = Tilemap.new(@viewport1)
    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
    for i in 0..6
      autotile_name = $game_map.autotile_names[i]
      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
    end
    @tilemap.map_data = $game_map.data
    @tilemap.priorities = $game_map.priorities
    # Make panorama plane
    @panorama = Plane.new(@viewport1)
    @panorama.z = -1000
    # Make fog plane
    @fog = Plane.new(@viewport1)
    @fog.z = 3000
    # Make fog2 plane
    @fog2 = Plane.new(@viewport1)
    @fog2.z = 3050
    # Make character sprites
    @character_sprites = []
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      @character_sprites.push(sprite)
    end
    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
    # Make weather
    @weather = RPG::Weather.new(@viewport1)
    # Make picture sprites
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures[i]))
    end
    # Make timer sprite
    @timer_sprite = Sprite_Timer.new
    # Frame update
    update
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    daniel_fog2_dispose
    @fog2.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    daniel_fog2_update
    if @fog2_name != $game_map.fog2_name or @fog2_hue != $game_map.fog2_hue
      @fog2_name = $game_map.fog2_name
      @fog2_hue = $game_map.fog2_hue
      if @fog2.bitmap != nil
        @fog2.bitmap.dispose
        @fog2.bitmap = nil
      end
      if @fog2_name != ""
        @fog2.bitmap = RPG::Cache.fog(@fog2_name, @fog2_hue)
      end
      Graphics.frame_reset
    end
    # Update fog2 plane
    @fog2.zoom_x = $game_map.fog2_zoom / 100.0
    @fog2.zoom_y = $game_map.fog2_zoom / 100.0
    @fog2.opacity = $game_map.fog2_opacity
    @fog2.blend_type = $game_map.fog2_blend_type
    @fog2.ox = $game_map.display_x / 4 + $game_map.fog2_ox
    @fog2.oy = $game_map.display_y / 4 + $game_map.fog2_oy
    @fog2.tone = $game_map.fog2_tone
  end
end
Expand to see the code.


Instructions

Place the script in a new script above main, make sure it is below Game_Map and Spriteset_Map. All the instructions on how to use the script are at the beginning of the script.

Credits and Thanks

Shinasura for requesting it.

Author's Notes

If you use the script in your game, please give credit to me. (Daniel3579)
Nice this actually quite useful
You had concerns about lag in the request thread. Did that turn out to be a problem?
edit
doesnt work, its not recognizing the filenames of the fogs. Do I need to call these in a specific order?
woot woot erm strange giving me credit but thanks ^_^
Thanks for making it!

I can't get it to work either Daniel. I think i'm having the same problem as ryan does. Otherwise, you've put all the features in a really useable way.

Also, just checking, but do you have to set every feature of it, like if you want it to just be normal blend, do you need to write 0 or can you just leave it?

I tried it in a new project too. I get an unitialised constant interpreter error
Considering the extractor didnt use english characters, I think this guy might have some "compatibility issues" with legal users.
OK, I see. If that is the case, is there any chance you can rectify these "issues", because you looked to have made it really well and it will come in really useful if it works as it should.
hmm im having the same problem too, causes problems if you use it with the dynamic shadows/sunlight thing(not tested it with reflections yet)
shinashura, that error goes away if you place this script above them all. At least it did with me. Not to say that it then worked... but I stopped getting an error about the light script, the sun script and the shadow script, and started getting the new one.
Quote:
You had concerns about lag in the request thread. Did that turn out to be a problem?

Nope, I thought it would be a problem but I had both scrolling at full speed and the game ran at 39-40 frames per second.

Quote:
doesnt work, its not recognizing the filenames of the fogs. Do I need to call these in a specific order?


Did you use the "Script..." command in an event command? This is how I did it and it works fine.
Event Spoiler
http://img163.imageshack.us/img163/5027/doublefogsscripttutorialrj2.png[/img]


Quote:
I can't get it to work either Daniel. I think i'm having the same problem as ryan does. Otherwise, you've put all the features in a really useable way.


Is it in the actual script or the event command script? If it is the actual script, could you post the error message and line it appears on?

Quote:
Also, just checking, but do you have to set every feature of it, like if you want it to just be normal blend, do you need to write 0 or can you just leave it?


You don't have to set it. It will be 0 by default. If you don't set something, it stays the default.
The problem for me was just that I wasn't putting the name of the fog in 'THESE', because I was just copying and pasting out of the intro to your script. I's suggest putting the word filename inside them.

But the script works great well done, it makes my map look so much better now. The lag nearly killed my comp, but then I tried again and it worked all of a sudden. Good stuff.
I'm glad it's working now, and what do you mean "THESE"?
I mean I wasn't writing the file name inside of inverted comma's, just alone cos it doesn't say to put them in inverted comma's in the instructions. BTW, whats the simplest way to turn a fog off then back on again?
If you want the fog to fade out, use this in a script event command:
$game_map.start_fog2_opacity_change(opacity, duration)
Expand to see the code.

So you would put 0 for opacity and how every many frames you want it to take as duration.
To fade back in, use the same thing but for opacity make it 64 or something.
okay, the only thing I was considering is that if you could turn it off and on via a switch, you may be able to reduce lag, where as changing the opacity wouldn't do that. howver, thinking about it, I could just set up an event with like 3 or 4 pages and have the fogs activities vary depending on switch operations. Thnaks for the script Daniel.
works like a charm now,thanks.I'll be sure to give the proper credit too
Daniel? I love the script, but quick question...

How would I set that up for a fog3 and fog4... for instance?

in case I want to have a LOT of birds in random places on a large fog for the overview, or if me and a bud were say, wanting to put some of the fogs BEHIND the tileset and some in front, use the battlers and create a parallaz scrolling cut-scene? your script is perfect, but how to expand it??
Yikes, you revived a year-old topic. Next time post it in RGSS Support!

Anyway, I'm not sure this script is meant to create 3 or 4 fogs, you'd have to further edit it, otherwise it would be called "Use Four Fogs at Once"...
Sure... but at least I got it fresh in people's mind... me and Arc were trying to figure out a way to utilize the fogs in a way that would allow parallax scrolling for 3d-ish cutscenes...
Hum.. just see what he edited and do the same but isntead of calling it fog2 put fog3 fog4 fog5 and so on..

Better way would be, creating a array, but since you don't know how to make it use the other it will be a litte pain in the ass to do it alone.

Good Luck!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=6498