Multi Layer Fog

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
Your script call is wrong, if what you have above is exactly what you typed (showing a screenshot of the event command is always better than just typing it, because I don't know if you've made a typo in the event, or just when putting it here). It should be tint_fog(arguments) not tint fog, arguments


To have it happen as soon as you enter the map, make the duration 0, and put it into a parallel process event that does an erase event right after doing the map setup.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,108
Reaction score
11,445
First Language
English
Primarily Uses
RMVXA
Still not getting it right.  Here is my event:

">
and here is the error message it produces:

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

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
That's a different error message than what you just said.


You've omitted the first parameter in the tint_fog call, which is the fog id.


tint_fog(1, -119, -81, -34, 85, 0)
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,108
Reaction score
11,445
First Language
English
Primarily Uses
RMVXA
The different error message is because I had made a different mistake in the formula.

I've got it to work, but I am still getting the tint change that we have been discussing in the other thread, so this pathway doesn't solve that problem, though perhaps with some juggling I can get it to look better than the option of using a tinted graphic. 

Anyway, this formula problem is now solved.  Thank you for your patience with an idiot.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
Yeah, let's leave that problem in the other thread, as you've already confirmed that it's not the fog script that's causing it :)
 

Allerka

Veteran
Veteran
Joined
Dec 31, 2012
Messages
289
Reaction score
71
First Language
English
Primarily Uses
Unfortunately, this one is doing the same thing as the XP-style script, and the fogs stick with me as I move around. Definitely weird, especially if it's basically ported straight from XP. Let me know if you need any screenshots.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
Try changing the Game_Fog.update_move method to this, and let me know if it's any better. I expect there might be issues with moving fog, where the direction might APPEAR to change when you're walking, depending on the direction of the fog movement and the direction of the PC's movement.

Code:
  #--------------------------------------------------------------------------  # * Update Fog Move  #--------------------------------------------------------------------------  def update_move    if @sx == 0      @ox = $game_map.display_x * 32 - @sx / 8.0    else      @ox -= @sx / 8.0    end        if @sy == 0      @oy = $game_map.display_y * 32 - @sy / 8.0    else      @oy -= @sy / 8.0    end  end
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,108
Reaction score
11,445
First Language
English
Primarily Uses
RMVXA
The fog still sticks to the party.  I made allowance for the direction of the fog and the direction of the player's movement, and even so, it was clear that the graphic just moved with the party's sprites.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
Strange - I used it without setting the sx and sy values, and the fog definitely stayed with the map - it didn't follow the player around. Then I set the sx and sy values and the fog moved, and it went faster or slower depending on whether the player was moving in the same direction or the opposite direction.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,108
Reaction score
11,445
First Language
English
Primarily Uses
RMVXA
I have just done it again, to be sure, and it's the same result.  If the player is standing still the fog is moving (and very nice it looks, too!), but once the player moves, the fog stays centred on the player.

Just to be sure that I didn't apply it incorrectly what I did is this: I amended the section 'Update Fog Move' which is below 'Frame Update' and above 'Update Fog Tone Change' by deleting what was there and copy/pasting in the code in your post.

My script call is:

show_fog(1, "alpha_fog", 0, 128, 0, 150, -2, 1)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
Maybe the -2 is the same speed in one direction that the player is moving in the other, so it LOOKS like it's staying with them, when it's actually moving in the opposite direction at the same speed as the player. If you move in the other direction, does it move again? Try experimenting with different speeds.
 

Allerka

Veteran
Veteran
Joined
Dec 31, 2012
Messages
289
Reaction score
71
First Language
English
Primarily Uses
Alright, tried the changes. It's partially fixed now. By default, I have my SX set to 2, and SY set to 0. If I move up and down, the fog/clouds stick to the map. But, if I move left or right, they stick to the character. If I set the SX to 0, then it sticks to the map in all directions.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
I have another idea. I'll tinker with it when I get back home today. Hopefully it'll fix the issues properly.
 

Candacis

Pixel Pusher
Restaff
Joined
May 2, 2012
Messages
1,525
Reaction score
2,161
First Language
German
Primarily Uses
First off, I tried and got the script to work, but I have the same problem, the fog moves with the player when they walk and this is not a good effect, if you want to have clouds. Is it possibly to have the fog move indepently?

It would also be very nice, if you could include an example of the script call in your Usage or the script itself. For instance, I don't know, what value or word I have to type in for the blend-type or hue.

my script call:

Code:
show_fog(1, "wolken", 0, 255, 0, 100, 1, 1, 200)
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,108
Reaction score
11,445
First Language
English
Primarily Uses
RMVXA
Hi, I was wondering if you had been able to find a fix for the problem of the fog sticking to the player instead of to the map?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
Well, I'm not sure what you guys are looking at, but when I put in a fog call with those parameters, the fog does not stick with the player. Maybe because the sx/sy values are so small, it LOOKS like that's what it's doing, because the player is moving fast enough to keep up with the fog. But if I look at the edge of the window, the fog is very clearly still moving. I suggest first you increase the speed of the fog a bit, just to see if the fog IS moving, and it's just the speed that makes it look like it's not.

I have made a change, and will provide it below, but personally I don't like it (it actually makes me feel ill when the player changes direction). Try the above, and if you are still convinced that the fog isn't moving, comment out the existing script and try this one instead.

#============================================================================# Multi Layer Fog# v1.0 by Shaz#----------------------------------------------------------------------------# This script lets you add one or more layers of fog to a map.# You can add vertical and/or horizontal scrolling to each fog layer.# You can have fog appear on top of the map or behind the map (above the# parallax layer).# You can adjust the fog's opacity and tone over time.#----------------------------------------------------------------------------# 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.## To add fog to a map, use the following in a Call Script event command:# show_fog(number, "filename", hue, opacity, blend_type, zoom, # speed-x, speed-y, z)# - only number and filename are mandatory# - fog is added like pictures - the number is simply an id (an array index),# and if you don't specify the z value, fog with a higher number/id is drawn# over fog with a lower number/id# - z position defaults to above the player. If you want to show fog above the # parallax layer but behind the map, use a negative value for z. The # parallax is drawn at -100## To change fog tone, use the following in a Call Script event command:# tint_fog(number, red, green, blue, gray, duration)## To change the fog opacity, use the following in a Call Script event command:# fade_fog(number, opacity, duration)## To remove fog, use the following in a Call Script event command:# erase_fog(number)## By default fog will be removed when you change maps, and battle screens # will have the same fog as the map. Change the CUSTOMIZATION options below# if you do not want this.#----------------------------------------------------------------------------# Terms:# Use in free or commercial games# Credit Shaz#============================================================================#============================================================================# CUSTOMIZATION## Set this to true or false to show (or not show) fog in the battle screenBATTLE_FOGS = true# Set this to true or false to clear (or not clear) fogs on transfer to new mapCLEAR_ON_TRANSFER = true# DO NOT CHANGE ANYTHING BELOW THIS LINE#============================================================================module Cache #-------------------------------------------------------------------------- # * Get Fog #-------------------------------------------------------------------------- def self.fog(filename, hue) load_bitmap("Graphics/Fogs/", filename, hue) endendclass Game_Screen #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :fogs #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias shaz_multi_fog_game_screen_initialize initialize def initialize @fogs = Game_Fogs.new shaz_multi_fog_game_screen_initialize end #-------------------------------------------------------------------------- # * Clear #-------------------------------------------------------------------------- alias shaz_multi_fog_game_screen_clear clear def clear shaz_multi_fog_game_screen_clear clear_fogs end #-------------------------------------------------------------------------- # * Clear Fogs #-------------------------------------------------------------------------- def clear_fogs @fogs.each {|fog| fog.erase} end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias shaz_multi_fog_game_screen_update update def update shaz_multi_fog_game_screen_update update_fogs end #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def update_fogs @fogs.each {|fog| fog.update} endend class Game_Fog #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :number attr_reader :name attr_reader :hue attr_reader :opacity attr_reader :blend_type attr_reader :zoom attr_reader :sx attr_reader :sy attr_reader :ox attr_reader :oy attr_reader :tone attr_reader :z #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(number) @number = number init_basic init_movement init_tone init_opacity end #-------------------------------------------------------------------------- # * Initialize Basic Variable #-------------------------------------------------------------------------- def init_basic @name = "" @hue = 90 @blend_type = 0 @zoom = 200 @sx = @sy = 0 end #-------------------------------------------------------------------------- # * Initialize Movement Variable #-------------------------------------------------------------------------- def init_movement @ox = @oy = 0 end #-------------------------------------------------------------------------- # * Initialize Tone #-------------------------------------------------------------------------- def init_tone @tone = Tone.new @tone_target = Tone.new @tone_duration = 0 end #-------------------------------------------------------------------------- # * Initialize Opacity #-------------------------------------------------------------------------- def init_opacity @opacity = 64.0 @opacity_target = 64.0 @opacity_duration = 0 end #-------------------------------------------------------------------------- # * Show Fog #-------------------------------------------------------------------------- def show(name, hue, opacity, blend_type, zoom, sx, sy, z) @name = name @hue = hue @opacity = opacity @blend_type = blend_type @zoom = zoom @sx = @sx2 = sx @sy = @sy2 = sy @z = z.nil? ? 300 + @number : z init_movement end #-------------------------------------------------------------------------- # * Start Changing Tone #-------------------------------------------------------------------------- def start_tone_change(tone, duration) @tone_target = tone.clone @tone_duration = duration @tone = @tone_target.clone if @tone_duration == 0 end #-------------------------------------------------------------------------- # * Start Opacity Change #-------------------------------------------------------------------------- def start_opacity_change(opacity, duration) @opacity_target = opacity * 1.0 @opacity_duration = duration @opacity = @opacity_target if @opacity_duration == 0 end #-------------------------------------------------------------------------- # * Erase Fog #-------------------------------------------------------------------------- def erase @name = "" end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update update_move update_tone_change update_opacity_change end #-------------------------------------------------------------------------- # * Update Fog Move #-------------------------------------------------------------------------- def update_move @sx2 -= @sx / 8.0 @sy2 -= @sy / 8.0 @ox = $game_map.display_x * 32 + @sx2 @oy = $game_map.display_y * 32 + @sy2 return end #-------------------------------------------------------------------------- # * Update Fog Tone Change #-------------------------------------------------------------------------- def update_tone_change return if @tone_duration == 0 d = @tone_duration target = @tone_target @tone.red = (@tone.red * (d - 1) + target.red) / d @tone.green = (@tone.green * (d - 1) + target.green) / d @tone.blue = (@tone.blue * (d - 1) + target.blue) / d @tone.gray = (@tone.gray * (d - 1) + target.gray) / d @tone_duration -= 1 end #-------------------------------------------------------------------------- # * Update Fog Opacity Change #-------------------------------------------------------------------------- def update_opacity_change return if @opacity_duration == 0 d = @opacity_duration @opacity = (@opacity * (d - 1) + @opacity_target) / d @opacity_duration -= 1 endendclass Game_Fogs #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize @data = [] end #-------------------------------------------------------------------------- # * Get Picture #-------------------------------------------------------------------------- def [](number) @data[number] ||= Game_Fog.new(number) end #-------------------------------------------------------------------------- # * Iterator #-------------------------------------------------------------------------- def each @data.compact.each {|fog| yield fog } if block_given? endendif CLEAR_ON_TRANSFER class Game_Player < Game_Character #-------------------------------------------------------------------------- # * Execute Player Transfer #-------------------------------------------------------------------------- alias shaz_multi_fog_game_player_perform_transfer perform_transfer def perform_transfer if transfer? && @new_map_id != $game_map.map_id $game_map.screen.fogs.each { |fog| fog.erase } end shaz_multi_fog_game_player_perform_transfer end endendclass Game_Interpreter #-------------------------------------------------------------------------- # * Show Fog #-------------------------------------------------------------------------- def show_fog(number, name, hue = 90, opacity = 64.0, blend_type = 0, zoom = 200, sx = 0, sy = 0, z = nil) screen.fogs[number].show(name, hue, opacity, blend_type, zoom, sx, sy, z) end #-------------------------------------------------------------------------- # * Tint Fog #-------------------------------------------------------------------------- def tint_fog(number, red, green, blue, gray, duration) screen.fogs[number].start_tone_change(Tone.new(red, green, blue, gray), duration) end #-------------------------------------------------------------------------- # * Change Fog Opacity #-------------------------------------------------------------------------- def fade_fog(number, opacity, duration) screen.fogs[number].start_opacity_change(opacity, duration) end #-------------------------------------------------------------------------- # * Erase Fog #-------------------------------------------------------------------------- def erase_fog(number) screen.fogs[number].erase endendclass Plane_Fog < Plane #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(viewport, fog) super(viewport) @fog = fog self.z = @fog.z self.zoom_x = @fog.zoom / 100 self.zoom_y = @fog.zoom / 100 self.blend_type = @fog.blend_type update end #-------------------------------------------------------------------------- # * Free #-------------------------------------------------------------------------- def dispose bitmap.dispose if bitmap super end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update update_bitmap update_move update_tone update_opacity end #-------------------------------------------------------------------------- # * Update Bitmap #-------------------------------------------------------------------------- def update_bitmap if @fog.name.empty? self.bitmap = nil else self.bitmap = Cache.fog(@fog.name, @fog.hue) end end #-------------------------------------------------------------------------- # * Update Move #-------------------------------------------------------------------------- def update_move self.ox = @fog.ox self.oy = @fog.oy end #-------------------------------------------------------------------------- # * Update Tone #-------------------------------------------------------------------------- def update_tone self.tone = @fog.tone end #-------------------------------------------------------------------------- # * Update Opacity #-------------------------------------------------------------------------- def update_opacity self.opacity = @fog.opacity endend class Spriteset_Map #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias shaz_multi_fog_spriteset_map_initialize initialize def initialize shaz_multi_fog_spriteset_map_initialize create_fogs update end #-------------------------------------------------------------------------- # * Create Fog Plane #-------------------------------------------------------------------------- def create_fogs @fog_planes = [] end #-------------------------------------------------------------------------- # * Free #-------------------------------------------------------------------------- alias shaz_multi_fog_spriteset_map_dispose dispose def dispose dispose_fogs shaz_multi_fog_spriteset_map_dispose end #-------------------------------------------------------------------------- # * Free Fog Plane #-------------------------------------------------------------------------- def dispose_fogs @fog_planes.compact.each {|fog| fog.dispose } end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias shaz_multi_fog_spriteset_map_update update def update update_fogs shaz_multi_fog_spriteset_map_update end #-------------------------------------------------------------------------- # * Update Fogs #-------------------------------------------------------------------------- def update_fogs return if !@fog_planes $game_map.screen.fogs.each do |fog| @fog_planes[fog.number] ||= Plane_Fog.new(@viewport1, fog) @fog_planes[fog.number].update end endendif BATTLE_FOGS class Spriteset_Battle #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias shaz_multi_fog_spriteset_battle_initialize initialize def initialize shaz_multi_fog_spriteset_battle_initialize create_fogs update end #-------------------------------------------------------------------------- # * Create Fog Plane #-------------------------------------------------------------------------- def create_fogs @fog_planes = [] end #-------------------------------------------------------------------------- # * Free #-------------------------------------------------------------------------- alias shaz_multi_fog_spriteset_map_dispose dispose def dispose dispose_fogs shaz_multi_fog_spriteset_map_dispose end #-------------------------------------------------------------------------- # * Free Fog Plane #-------------------------------------------------------------------------- def dispose_fogs @fog_planes.compact.each {|fog| fog.dispose } end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias shaz_multi_fog_spriteset_map_update update def update update_fogs shaz_multi_fog_spriteset_map_update end #-------------------------------------------------------------------------- # * Update Fogs #-------------------------------------------------------------------------- def update_fogs return if !@fog_planes $game_map.screen.update_fogs $game_map.screen.fogs.each do |fog| @fog_planes[fog.number] ||= Plane_Fog.new(@viewport1, fog) @fog_planes[fog.number].update end end endend # BATTLE_FOGS
As for the parameters? You could simply go into the help file and do a search for hue, opacity, blend_type to get the possible values. I didn't elaborate on them because they're already used for other things, and the ranges are the same.

Hue = 0 - 360

Opacity = 0 (fully transparent) - 255 (fully opaque)

Blend Mode = 0 (normal; default), 1 (add - lighter colour), 2 (subtract - darker colour)

You could also look at the Game_Interpreter section of the script and see what the default values are (for instance, the default for fog opacity - copied from XP's Show Fog command - is 64.0)
 
Last edited by a moderator:

Allerka

Veteran
Veteran
Joined
Dec 31, 2012
Messages
289
Reaction score
71
First Language
English
Primarily Uses
Quite certain. Let me put it into video form for you to see what's going on. Ignore the wacky hues in the XP part, the software I had to use for recording from there (since FRAPS doesn't like XP) is garbage (I basically have to choose between either laggy framerates or random hue shifts). But the settings are the same in all three instances (SX = 2, SY = 0). I cranked up the opacity to make the clouds easier to see.

The good news is, your update fixed the issue. Everything seems to be working fine for me now.
 

Candacis

Pixel Pusher
Restaff
Joined
May 2, 2012
Messages
1,525
Reaction score
2,161
First Language
German
Primarily Uses
It seems this really was only a problem with slow moving fog. I had my settings on SX = 1, SY = 1.

Allerka's video shows the problem perfectly.

Shaz, thanks for the update and for taking the time to do this!

It fixed the problem for me and I like this version a lot more.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,633
Reaction score
13,225
First Language
English
Primarily Uses
RMMV
Thanks for the video Allerka, but I don't believe it shows an issue at all. Yes, if you walk in the same direction the fog is moving, it LOOKS like it is not moving (or is moving more slowly), BECAUSE your fog movement is slow enough that the player is almost walking as fast. But if you look at the edge of the map, you CAN see that the fog IS still moving. It is that way also IRL. If a plane flies in the opposite direction of a moving cloud, it looks like the cloud is moving more quickly. But if it flies in the same direction, it looks like the cloud is moving more slowly (or that the plane is moving faster than the cloud, so the cloud looks like it is moving backwards).


I am still not convinced this problem exists. So I'm glad Candacis that you like the new version, and I'll leave it in this post, but I don't like it, and won't be updating the pastebin version with it (at this stage). I can only suggest that people try and make the fog move a little faster so it's more obvious that it IS still moving.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

I have been listening to the new music tracks for MZ included in the sample game projects ... for way too long. Quite catchy!
Small rant: While using SRD Hud maker for a battle hud, I typed in the wrong script call and got an error, but then forgot to delete the piece that caused the error before closed the Hud maker and hit F5 to restart the game. Now everytime I engage in a battle my game crashes...
:kaolivid:
Would Jump into Javascript be best off continuing to break down the MV core files, or would people prefer a quick detour to cover everything that's changed in the core from MV to MZ?

Forum statistics

Threads
100,532
Messages
976,931
Members
132,081
Latest member
Kaezyelnatz
Top