-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCharacter Animation Loop.rb
232 lines (200 loc) · 6.37 KB
/
Character Animation Loop.rb
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# =============================================================================
# TheoAllen - Character Animation Loop
# Version : 1.1b
# =============================================================================
($imported ||= {})[:Theo_CharAnimloop] = true
# =============================================================================
# Change Logs:
# -----------------------------------------------------------------------------
# 2018.08.07 - Added bottom flag
# 2018.07.15 - Fixes script efficiency for less fps drop
# 2014.02.12 - Finished script
# =============================================================================
=begin
-----------------------------------------------------------------------------
Intro :
This script allow you to play animation on map sprite, loop it, and follow
the character
-----------------------------------------------------------------------------
How to use :
Put this script below material and above main
Use these script call in SET MOVE ROUTE (pick one u need)
animloop(id)
animloop(id, mirror)
animloop(id, mirror, rate)
animloop(id, mirror, rate, bottom)
id > animation id in database
mirror > will animation will be mirrored? (true/false)
rate > animation speed. Put in from range 1 ~ 4
bottom > true/false. If set to true, will play behind the sprite. Default
is false
If you just want to play animation on the back, just have to fill ALL the
others even though u don't need it. For example
animloop(66, false, 3, true)
To stop animation, write a script call
end_animloop
-----------------------------------------------------------------------------
Terms of use :
Credit me, TheoAllen. You are free to edit this script by your own. As long
as you don't claim it yours. For commercial purpose, don't forget to give me
a free copy of the game.
=end
#==============================================================================
# No config whatsoever
#==============================================================================
class Game_Character
attr_accessor :animloop_id
attr_accessor :animloop_mirror
attr_accessor :animloop_rate
attr_accessor :animloop_bottom
alias theo_animloop_id_init initialize
def initialize
theo_animloop_id_init
init_animloop_members
end
def init_animloop_members
@animloop_id = 0
@animloop_mirror = false
@animloop_rate = 3
@animloop_bottom = false
end
def animloop(id, mirror = false, rate = 3, bottom = false)
@animloop_id = id
@animloop_mirror = mirror
@animloop_rate = rate
@animloop_bottom = bottom
sprset = get_spriteset
return unless sprset
spr = get_spriteset.get_sprite(self)
get_spriteset.get_sprite(self).end_animation if spr
end
def end_animloop
init_animloop_members
end
def animloop_id
return @animloop_id ||= 0
end
end
#------------------------------------------------------------------------------
# Pseudo Sprite for animation
#------------------------------------------------------------------------------
class Char_Animloop < Sprite_Base
attr_reader :char_sprite
def initialize(char_sprite)
super(char_sprite.viewport)
@char_sprite = char_sprite
update_all
end
def update_all
src_rect.set(char_sprite.src_rect)
self.ox = char_sprite.ox
self.oy = char_sprite.oy
last_x = char_sprite.x - self.x
last_y = char_sprite.y - self.y
move_animation(last_x, last_y)
self.x = char_sprite.x
self.y = char_sprite.y
self.z = char_sprite.z
end
def update
super
update_all
setup_animation
end
def setup_animation
if !animation? && character.animloop_id != 0
@anim_id = character.animloop_id
start_animation($data_animations[@anim_id], character.animloop_mirror)
end
end
def character
char_sprite.character
end
def end_animation
if character.animloop_id == @anim_id
@ani_duration = @animation.frame_max * @ani_rate + 1
# Revert back
elsif character.animloop_id != @anim_id && character.animloop_id != 0
@anim_id = character.animloop_id
start_animation($data_animations[@anim_id], character.animloop_mirror)
# Change animation
else
@anim_id = 0
super
# End animation
end
end
def move_animation(dx, dy)
if @animation && @animation.position != 3
@ani_ox += dx
@ani_oy += dy
@ani_sprites.each do |sprite|
sprite.x += dx
sprite.y += dy
end
end
end
def set_animation_rate
@ani_rate = character.animloop_rate
end
def animation_set_sprites(frame)
cell_data = frame.cell_data
@ani_sprites.each_with_index do |sprite, i|
next unless sprite
pattern = cell_data[i, 0]
if !pattern || pattern < 0
sprite.visible = false
next
end
sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
sprite.visible = true
sprite.src_rect.set(pattern % 5 * 192,
pattern % 100 / 5 * 192, 192, 192)
if @ani_mirror
sprite.x = @ani_ox - cell_data[i, 1]
sprite.y = @ani_oy + cell_data[i, 2]
sprite.angle = (360 - cell_data[i, 4])
sprite.mirror = (cell_data[i, 5] == 0)
else
sprite.x = @ani_ox + cell_data[i, 1]
sprite.y = @ani_oy + cell_data[i, 2]
sprite.angle = cell_data[i, 4]
sprite.mirror = (cell_data[i, 5] == 1)
end
zpos = character.animloop_bottom ? 50 - 17 : 300
sprite.z = self.z + zpos + i
sprite.ox = 96
sprite.oy = 96
sprite.zoom_x = cell_data[i, 3] / 100.0
sprite.zoom_y = cell_data[i, 3] / 100.0
sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
sprite.blend_type = cell_data[i, 7]
end
end
end
class Sprite_Character
alias theo_animloop_id_update update
def update
theo_animloop_id_update
if character.animloop_id > 0 && !@sprite_animloop
@sprite_animloop = Char_Animloop.new(self)
end
@sprite_animloop.update if @sprite_animloop
end
alias theo_animloop_id_dispose dispose
def dispose
theo_animloop_id_dispose
@sprite_animloop.dispose if @sprite_animloop
end
end
class Spriteset_Map
def get_sprite(char)
@character_sprites.find {|c| c.character == char}
end
end
def get_spriteset
get_scene.instance_variable_get("@spriteset")
end
def get_scene
SceneManager.scene
end