1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
| =begin
Change Character Opacity in Frames 2.1.1
by PK8
Created: 5/12/2009
Modified: 6/11/2012
──────────────────────────────────────────────────────────────────────────────
■ Introduction
This allows game creators to change the opacity of character sprites to a
certain amount in a set number of frames.
──────────────────────────────────────────────────────────────────────────────
■ Features
Change the opacity of a character's sprite in a certain number of frames
with a script call.
──────────────────────────────────────────────────────────────────────────────
■ Usage
Script call for changing the player's sprite opacity:
$game_player.opacity_change(opacity, duration, relative)
Script call for changing an event's sprite opacity:
$game_map.events[id].opacity_change(opacity, duration, relative)
Script call for changing a vehicle's sprite opacity:
$game_map.vehicle[id].opacity_change(opacity, duration, relative)
* 0: Boat, 1: Ship, 2: Airship
opacity: Min: 0, Max: 255
duration: Min: 0
relative: true or false (Optional. Defaults to false)
──────────────────────────────────────────────────────────────────────────────
■ Examples
This would lower the player's sprite opacity by 20 in 20 frames
$game_player.opacity_change(-20, 20, true)
This would raise the player's sprite opacity back up by 20 in 20 frames
$game_player.opacity_change(20, 20, true)
──────────────────────────────────────────────────────────────────────────────
■ What's New? (MM/DD/YYYY)
v1 (05/12/2009): Initial release
v2 (04/11/2012): Recoded.
v2.1 (04/15/2012): Adds new relative argument to opacity_change
v2.1.1 (06/11/2012): Shortened the code, made @opacity, @opacity_target, and
@opacity_duration accessible via script call, and
improved the documentation.
──────────────────────────────────────────────────────────────────────────────
■ Methods Aliased
o Game_Character.initialize
o Game_Character.update
=end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :opacity, :opacity_target, :opacity_duration
#---------------------------------------------------------------------------
# * Alias Listings
#---------------------------------------------------------------------------
unless method_defined?(:pk8_cco_initialize)
alias_method(:pk8_cco_initialize, :initialize)
alias_method(:pk8_cco_update, :update)
end
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize; pk8_cco_initialize; @opacity_target,@opacity_duration=0,0; end
#--------------------------------------------------------------------------
# * Opacity Change
# opacity : Target opacity. (0 - 255)
# duration : Frame amount.
# relative : References current value and adds to it, if true.
#--------------------------------------------------------------------------
def opacity_change(opacity, duration, relative = false)
@opacity_target = (relative == true ? @opacity + opacity : opacity)
@opacity_duration = duration
@opacity = @opacity_target.clone if @opacity_duration == 0
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
pk8_cco_update
if @opacity_duration >= 1
d = @opacity_duration
@opacity = (@opacity * (d - 1) + @opacity_target) / d
@opacity_duration -= 1
end
end
end |