=begin #=============================================================================== Title: Character Sprite Opacity Author: Hime Date: Jan 11, 2015 -------------------------------------------------------------------------------- ** Change log Jan 11, 2015 - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script allows you to control a character's opacity settings on the map. You can increase or decrease the opacity, turning the character fully opaque (value of 255), or completely transparent (value of 0). You can control how long the opacity change will take. For example, if you wanted to fade from 255 to 0 over a span of 60 frames, the game will automatically calculate the appropriate opacities over the 60 frames so you don't have to do it yourself. -------------------------------------------------------------------------------- ** Installation In the script editor, place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage You can change opacity settings for different types of characters, including events, the player, and vehicles. -- Events -- To change event opacity, use the script call change_event_opacity(id, opacity, duration, wait) Where the ID is the ID of the event, and the opacity is the opacity you want to change it to If the `duration` is specified, that is the number of frames the opacity change will occur. If it is omitted, the change will occur immediately (duration 0) `wait` tells the game to wait while the opacity change occurs. This is useful if you want it to wait until the change has finished. By default, the game will wait until it if finished. -- Player -- To change player opacity, use one of the script calls change_player_opacity(opacity, duration, wait) By default, followers have the same opacity setting as the player. -- Vehicles -- To change vehicle opacities, use the script call change_vehicle_opacity(type, opacity, duration, wait) The type is the type of vehicle you want to change. By default, these are provided: :boat :ship :airship Do not forget the colon. -------------------------------------------------------------------------------- ** Example To turn event 4 invisible over a period of 60 frames, use the script call change_event_opacity(4, 0, 60) If you don't want the game to wait while the change occurs, use the script call change_event_opacity(4, 0, 60, false) Changing the opacity of the airship to half-transparent would be like change_vehicle_opacity(:airship, 128) #=============================================================================== =end $imported = {} if $imported.nil? $imported[:TH_CharacterSpriteOpacity] = true #=============================================================================== # ** Rest of the script #=============================================================================== class Game_Character < Game_CharacterBase attr_reader :target_opacity_duration alias :th_character_sprite_opacity_init_private_members :init_private_members def init_private_members th_character_sprite_opacity_init_private_members @target_opacity = @opacity @target_opacity_duration = 0 end alias :th_character_sprite_opacity_update :update def update th_character_sprite_opacity_update update_opacity end def change_opacity(opacity, duration) @target_opacity = opacity @target_opacity_duration = duration @opacity = opacity if duration == 0 end def update_opacity if @target_opacity_duration > 0 d = @target_opacity_duration @opacity = (@opacity * (d - 1) + @target_opacity) / d @target_opacity_duration -= 1 end end end class Game_Interpreter def change_character_opacity(char, opacity, duration=0, wait=true) char.change_opacity(opacity, duration) Fiber.yield while char.target_opacity_duration > 0 if wait end def change_event_opacity(id, opacity, duration=0, wait=true) char = get_character(id) change_character_opacity(char, opacity, duration, wait) end def change_player_opacity(opacity, duration=0, wait=true) change_character_opacity($game_player, opacity, duration, wait) end def change_follower_opacity(id, opacity, duration=0, wait=true) char = $game_player.followers[id-1] change_character_opacity(char, opacity, duration, wait) end def change_vehicle_opacity(type, opacity, duration=0, wait=true) case type when :ship char = $game_map.ship when :boat char = $game_map.boat when :airship char = $game_map.airship end change_character_opacity(char, opacity, duration, wait) end end