Home > RGSS Script Reference > Sprite_Battler
Sprite_Battler
Inherits from: Sprite
Description: This class performs graphical changes on battler sprites, such as updating whether the battler graphic is visible, making it flash before attacking, and showing damage dealt to the battler.
class Sprite_Battler < RPG::Sprite
# ------------------------------------
attr_accessor :battler
# ------------------------------------
def initialize(viewport, battler = nil)
super(viewport)
@battler = battler
@battler_visible = false
end
# ------------------------------------
def dispose
if self.bitmap != nil
self.bitmap.dispose
end
super
end
# ------------------------------------
def update
super
if @battler == nil
if self.bitmap != nil
self.bitmap.dispose
end
self.bitmap = nil
return
end
if @battler.battler_name != @battler_name or
@battler.battler_hue != @battler_hue
@battler_name = @battler.battler_name
@battler_hue = @battler.battler_hue
self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
@width = bitmap.width
@height = bitmap.height
self.ox = @width / 2
self.oy = @height
if @battler.dead? or @battler.hidden
self.opacity = 0
end
end
if @battler.damage == nil and
@battler.state_animation_id != @state_animation_id
@state_animation_id = @battler.state_animation_id
loop_animation($data_animations[@state_animation_id])
end
if @battler.is_a?(Game_Actor) and
not @battler.hidden and not @battler.dead?
if $game_temp.battle_main_phase
self.opacity += 3 if self.opacity < 255
else
self.opacity -= 3 if self.opacity > 207
end
end
if @battler.blink
blink_on
else
blink_off
end
unless @battler_visible
if not @battler.hidden and not @battler.dead?
appear
@battler_visible = true
end
end
if @battler_visible
if @battler.hidden
$game_system.se_play($data_system.escape_se)
escape
@battler_visible = false
end
if @battler.white_flash
whiten
@battler.white_flash = false
end
if @battler.animation_id != 0
animation = $data_animations[@battler.animation_id]
animation(animation, @battler.animation_hit)
@battler.animation_id = 0
end
if @battler.damage_pop
damage(@battler.damage, @battler.critical)
@battler.damage = nil
@battler.critical = false
@battler.damage_pop = false
end
if @battler.damage == nil and @battler.dead?
if @battler.is_a?(Game_Enemy)
$game_system.se_play($data_system.enemy_collapse_se)
else
$game_system.se_play($data_system.actor_collapse_se)
end
collapse
@battler_visible = false
end
end
self.x = @battler.screen_x
self.y = @battler.screen_y
self.z = @battler.screen_z
end
end
|
Battler: The Game_Battler object this sprite represents.
Battler_Visible: This flag is true if the battler is not hidden or dead, false otherwise.
Battler_Name: The filename of the battler graphic.
Battler_Hue: The sprite's hue modification value.
Width: The width of the battler graphic, in pixels.
Height: The height of the battler graphic, in pixels.
State_Animation_ID: The ID of the animation to play for the battler's highest-priority status effect.
Initialize
Arguments: None
Local Variables: None
How it Works: This method sets the battler which the sprite belongs and the battler's initial visibility to false.
Dispose
Arguments: None
Local Variables: None
How it Works: This method is the garbage collection method for this sprite. It first sets the sprite's bitmap to nil, then disposes of that bitmap. It then calls Sprite#Dispose in order to do further garbage collection.
Update
Arguments: None
Local Variables: None
How it Works: This method update's the sprite's graphical state each frame. What exactly the call to super does is a mystery, since the Sprite class isn't visible to the user. The first check the method performs is to see if @battler is nil. If it is, then the battler's bitmap is set to nil and then the Bitmap#Dispose method is called to get rid of the bitmap's memory allocation. The if @battler.battler_name != @battler_name or @battler.battler_hue != @battler_hue clause checks to see if the battler's image has been changed as a result of the "Change Hero Graphics" event command. If either one of the conditions in the clause is true, then @battler_name and @battler_hue get set to the new graphics the user has chosen. The self.ox = @width / 2 statement centers the battler image within its viewport, and the self.oy = @height statement places it at the proper height within the viewport. The next statement checks to see if the battler is dead or hidden. If either of these is true, then @battler.opacity is set to 0 (completely transparent). The if @battler.damage == nil and @battler.state_animation_id != @state_animation_id statement handles changing the looping animation for status effects on battlers. If the current status effect ID is not equal to the new one, and the battler is currently undamaged, then the loop_animation($data_animations[@state_animation_id]) call starts looping the status effect animation. The next clause checks to see if the battler is a Game_Actor object. If the battler is, then the method checks to see if the battle is currently in Phase 4 (Main Phase). If so, then the battler's opacity is increased by 3 if the battler's opacity is less than 255. If not, then the battler's opacity is reduced by 3 if the battler's opacity is greater than 207. The if @battler.blink clause checks to see if the battler should be blinking because it is waiting for command entry. If it is, then the Sprite#Blink_On method is called. If not, then the Sprite#Blink_Off method is called. The unless @battler_visible clause checks to see if the battler's hidden flag is been cleared, and it's not dead. This means that the "Show Hidden Monster" event command has been used, so the battler appears and the @battler_visible flag is set to true. Conversely, if the battler's hidden flag has been set and the battler isn't dead, then the battler has escaped, so the escape sound effect is played and the battler becomes invisible. The if @battler.white_flash clause checks to see if the battler should flash because it's about to take an action in battle. If it is, then the Sprite#Whiten method is called to turn the battler white momentarily, then the white flash flag is cleared. Next, the method checks to see if there's an animation waiting to play on the battler, either because of a battle action or a "Show Battle Animation" event command. The animation is then played on the character, and the value of @battler.animation_id is reset to 0. The if @battler.damage_pop clause checks to see if damage is waiting to resolve on this battler. If it is, then the damage function is called to show the damage on the battler, and the damage, critical, and damage resolution values are all cleared. The if @battler.damage == nil and @battler.dead? clause checks to see if the battler should collapse because it has died. If the battler is a Game_Enemy object, then the enemy collapse sound effect is played. Otherwise, the actor collapse sound effect is played. The Sprite#Collapse method handles the collapse animation. The final three statements update the coordinates of the sprites on the screen if they have changed.
|
|