Class: Sprite_Character
- Inherits:
-
Sprite_Base
- Object
- Sprite
- Sprite_Base
- Sprite_Character
- Defined in:
- lib/rgss3_default_scripts/Sprite_Character.rb
Overview
** Sprite_Character
This sprite is used to display characters. It observes an instance of the
Game_Character class and automatically changes sprite state.
Instance Attribute Summary collapse
-
#character ⇒ Object
————————————————————————– * Public Instance Variables ————————————————————————–.
Instance Method Summary collapse
-
#balloon_frame_index ⇒ Object
————————————————————————– * Frame Number of Balloon Icon ————————————————————————–.
-
#balloon_speed ⇒ Object
————————————————————————– * Balloon Icon Display Speed ————————————————————————–.
-
#balloon_wait ⇒ Object
————————————————————————– * Wait Time for Last Frame of Balloon ————————————————————————–.
-
#dispose ⇒ Object
————————————————————————– * Free ————————————————————————–.
-
#dispose_balloon ⇒ Object
————————————————————————– * Free Balloon Icon ————————————————————————–.
-
#end_animation ⇒ Object
————————————————————————– * End Animation ————————————————————————–.
-
#end_balloon ⇒ Object
————————————————————————– * End Balloon Icon ————————————————————————–.
-
#graphic_changed? ⇒ Boolean
————————————————————————– * Determine if Graphic Changed ————————————————————————–.
-
#initialize(viewport, character = nil) ⇒ Sprite_Character
constructor
————————————————————————– * Object Initialization character : Game_Character ————————————————————————–.
-
#move_animation(dx, dy) ⇒ Object
————————————————————————– * Move Animation ————————————————————————–.
-
#set_character_bitmap ⇒ Object
————————————————————————– * Set Character Bitmap ————————————————————————–.
-
#set_tile_bitmap ⇒ Object
————————————————————————– * Set Tile Bitmap ————————————————————————–.
-
#setup_new_effect ⇒ Object
————————————————————————– * Set New Effect ————————————————————————–.
-
#start_balloon ⇒ Object
————————————————————————– * Start Balloon Icon Display ————————————————————————–.
-
#tileset_bitmap(tile_id) ⇒ Object
————————————————————————– * Get Tileset Image That Includes the Designated Tile ————————————————————————–.
-
#update ⇒ Object
————————————————————————– * Frame Update ————————————————————————–.
-
#update_balloon ⇒ Object
————————————————————————– * Update Balloon Icon ————————————————————————–.
-
#update_bitmap ⇒ Object
————————————————————————– * Update Transfer Origin Bitmap ————————————————————————–.
-
#update_other ⇒ Object
————————————————————————– * Update Other ————————————————————————–.
-
#update_position ⇒ Object
————————————————————————– * Update Position ————————————————————————–.
-
#update_src_rect ⇒ Object
————————————————————————– * Update Transfer Origin Rectangle ————————————————————————–.
Methods inherited from Sprite_Base
#animation?, #animation_process_timing, #animation_set_sprites, #dispose_animation, #load_animation_bitmap, #make_animation_sprites, #set_animation_origin, #set_animation_rate, #start_animation, #update_animation
Constructor Details
#initialize(viewport, character = nil) ⇒ Sprite_Character
-
Object Initialization
character : Game_Character
17 18 19 20 21 22 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 17 def initialize(, character = nil) super() @character = character @balloon_duration = 0 update end |
Instance Attribute Details
#character ⇒ Object
-
Public Instance Variables
12 13 14 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 12 def character @character end |
Instance Method Details
#balloon_frame_index ⇒ Object
-
Frame Number of Balloon Icon
223 224 225 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 223 def balloon_frame_index return 7 - [(@balloon_duration - balloon_wait) / balloon_speed, 0].max end |
#balloon_speed ⇒ Object
-
Balloon Icon Display Speed
211 212 213 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 211 def balloon_speed return 8 end |
#balloon_wait ⇒ Object
-
Wait Time for Last Frame of Balloon
217 218 219 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 217 def balloon_wait return 12 end |
#dispose ⇒ Object
-
Free
26 27 28 29 30 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 26 def dispose end_animation end_balloon super end |
#dispose_balloon ⇒ Object
-
Free Balloon Icon
177 178 179 180 181 182 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 177 def dispose_balloon if @balloon_sprite @balloon_sprite.dispose @balloon_sprite = nil end end |
#end_animation ⇒ Object
-
End Animation
158 159 160 161 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 158 def end_animation super @character.animation_id = 0 end |
#end_balloon ⇒ Object
-
End Balloon Icon
204 205 206 207 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 204 def end_balloon dispose_balloon @character.balloon_id = 0 end |
#graphic_changed? ⇒ Boolean
-
Determine if Graphic Changed
67 68 69 70 71 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 67 def graphic_changed? @tile_id != @character.tile_id || @character_name != @character.character_name || @character_index != @character.character_index end |
#move_animation(dx, dy) ⇒ Object
-
Move Animation
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 145 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 |
#set_character_bitmap ⇒ Object
-
Set Character Bitmap
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 86 def set_character_bitmap self.bitmap = Cache.character(@character_name) sign = @character_name[/^[\!\$]./] if sign && sign.include?('$') @cw = bitmap.width / 3 @ch = bitmap.height / 4 else @cw = bitmap.width / 12 @ch = bitmap.height / 8 end self.ox = @cw / 2 self.oy = @ch end |
#set_tile_bitmap ⇒ Object
-
Set Tile Bitmap
75 76 77 78 79 80 81 82 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 75 def set_tile_bitmap sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32; sy = @tile_id % 256 / 8 % 16 * 32; self.bitmap = tileset_bitmap(@tile_id) self.src_rect.set(sx, sy, 32, 32) self.ox = 16 self.oy = 32 end |
#setup_new_effect ⇒ Object
-
Set New Effect
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 132 def setup_new_effect if !animation? && @character.animation_id > 0 animation = $data_animations[@character.animation_id] start_animation(animation) end if !@balloon_sprite && @character.balloon_id > 0 @balloon_id = @character.balloon_id start_balloon end end |
#start_balloon ⇒ Object
-
Start Balloon Icon Display
165 166 167 168 169 170 171 172 173 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 165 def start_balloon dispose_balloon @balloon_duration = 8 * balloon_speed + balloon_wait @balloon_sprite = ::Sprite.new() @balloon_sprite.bitmap = Cache.system("Balloon") @balloon_sprite.ox = 16 @balloon_sprite.oy = 32 update_balloon end |
#tileset_bitmap(tile_id) ⇒ Object
-
Get Tileset Image That Includes the Designated Tile
46 47 48 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 46 def tileset_bitmap(tile_id) Cache.tileset($game_map.tileset.tileset_names[5 + tile_id / 256]) end |
#update ⇒ Object
-
Frame Update
34 35 36 37 38 39 40 41 42 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 34 def update super update_bitmap update_src_rect update_position update_other update_balloon setup_new_effect end |
#update_balloon ⇒ Object
-
Update Balloon Icon
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 186 def update_balloon if @balloon_duration > 0 @balloon_duration -= 1 if @balloon_duration > 0 @balloon_sprite.x = x @balloon_sprite.y = y - height @balloon_sprite.z = z + 200 sx = balloon_frame_index * 32 sy = (@balloon_id - 1) * 32 @balloon_sprite.src_rect.set(sx, sy, 32, 32) else end_balloon end end end |
#update_bitmap ⇒ Object
-
Update Transfer Origin Bitmap
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 52 def update_bitmap if graphic_changed? @tile_id = @character.tile_id @character_name = @character.character_name @character_index = @character.character_index if @tile_id > 0 set_tile_bitmap else set_character_bitmap end end end |
#update_other ⇒ Object
-
Update Other
123 124 125 126 127 128 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 123 def update_other self.opacity = @character.opacity self.blend_type = @character.blend_type self.bush_depth = @character.bush_depth self.visible = !@character.transparent end |
#update_position ⇒ Object
-
Update Position
114 115 116 117 118 119 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 114 def update_position move_animation(@character.screen_x - x, @character.screen_y - y) self.x = @character.screen_x self.y = @character.screen_y self.z = @character.screen_z end |
#update_src_rect ⇒ Object
-
Update Transfer Origin Rectangle
102 103 104 105 106 107 108 109 110 |
# File 'lib/rgss3_default_scripts/Sprite_Character.rb', line 102 def update_src_rect if @tile_id == 0 index = @character.character_index pattern = @character.pattern < 3 ? @character.pattern : 1 sx = (index % 4 * 3 + pattern) * @cw sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch self.src_rect.set(sx, sy, @cw, @ch) end end |