Home > RGSS Script Reference > Spriteset_Battle
Spriteset_Battle
Inherits from: None
Description: This class contains the set of sprites used in the Scene_Battle class, such as the enemies, actors, battle background, and any pictures being displayed.
class Spriteset_Battle
# ------------------------------------
attr_reader :viewport1
attr_reader :viewport2
# ------------------------------------
def initialize
@viewport1 = Viewport.new(0, 0, 640, 320)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport4 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 101
@viewport3.z = 200
@viewport4.z = 5000
@battleback_sprite = Sprite.new(@viewport1)
@enemy_sprites = []
for enemy in $game_troop.enemies.reverse
@enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy))
end
@actor_sprites = []
@actor_sprites.push(Sprite_Battler.new(@viewport2))
@actor_sprites.push(Sprite_Battler.new(@viewport2))
@actor_sprites.push(Sprite_Battler.new(@viewport2))
@actor_sprites.push(Sprite_Battler.new(@viewport2))
@weather = RPG::Weather.new(@viewport1)
@picture_sprites = []
for i in 51..100
@picture_sprites.push(Sprite_Picture.new(@viewport3,
$game_screen.pictures[i]))
end
@timer_sprite = Sprite_Timer.new
update
end
# ------------------------------------
def dispose
if @battleback_sprite.bitmap != nil
@battleback_sprite.bitmap.dispose
end
@battleback_sprite.dispose
for sprite in @enemy_sprites + @actor_sprites
sprite.dispose
end
@weather.dispose
for sprite in @picture_sprites
sprite.dispose
end
@timer_sprite.dispose
@viewport1.dispose
@viewport2.dispose
@viewport3.dispose
@viewport4.dispose
end
# ------------------------------------
def effect?
for sprite in @enemy_sprites + @actor_sprites
return true if sprite.effect?
end
return false
end
# ------------------------------------
def update
@actor_sprites[0].battler = $game_party.actors[0]
@actor_sprites[1].battler = $game_party.actors[1]
@actor_sprites[2].battler = $game_party.actors[2]
@actor_sprites[3].battler = $game_party.actors[3]
if @battleback_name != $game_temp.battleback_name
@battleback_name = $game_temp.battleback_name
if @battleback_sprite.bitmap != nil
@battleback_sprite.bitmap.dispose
end
@battleback_sprite.bitmap = RPG::Cache.battleback(@battleback_name)
@battleback_sprite.src_rect.set(0, 0, 640, 320)
end
for sprite in @enemy_sprites + @actor_sprites
sprite.update
end
@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.update
for sprite in @picture_sprites
sprite.update
end
@timer_sprite.update
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
@viewport4.color = $game_screen.flash_color
@viewport1.update
@viewport2.update
@viewport4.update
end
end
|
Viewport1: The viewport for the weather effect, enemies, and battle background.
Viewport2: The viewport for the actor sprites.
Viewport3: The viewport for the pictures being shown on the battle screen.
Viewport4: The viewport for any "Flash Screen" effects being shown on the battle screen.
Battleback_Sprite: A Sprite object representing the battle background.
Enemy_Sprites: An array of Sprite_Battler objects representing the monsters in the battle.
Actor_Sprites: An array of Sprite_Battler objects representing the actors in the battle.
Weather: An RPG::Weather object that represents the weather effect sprite being shown on the screen.
Picture_Sprites: An array containing fiftySprite_Picture objects representing the pictures being shown in battle.
Timer_Sprite: The Sprite_Timer object for the timer.
Initialize
Arguments: None
Local Variables: None
How it Works: This method initializes the spriteset. Each of the four viewports accomodates a different set of sprite objects (see the Properties section above). Each viewport's z-index determines which viewport's sprites will take precedence if they occupy the same space. Viewport #1 has the default z-index of 100, so it will have the lowest priority. Viewports #2, #3, and #4, have z-indexes of 101, 200, and 5000, respectively, so the higher-numbered viewports have the highest priority. The battle background sprite is first assigned to viewport #1. Then, each of the monster sprites is pushed into the @enemy_sprites array. These sprites are also assigned to viewport #1. Next, each of the four actor sprites is pushed onto the @actor_sprites array, and assigned to viewport #2. Then, the weather is set up and assigned to viewport #1. Each of the fifty picture sprites are then set up in turn, and assigned to viewport #3. Finally, the timer sprite is updated, and strangely not assigned to a viewport.
Dispose
Arguments: None
Local Variables: None
How it Works: The method calls the Sprite#Dispose method for each sprite in the spriteset.
Effect?
Arguments: None
Local Variables: None
How it Works: This method determines if an effect is resolving on one or more sprites in the spriteset. This method returns true if for any sprite in either the @enemy_sprites or @actor_sprites arrays, the Sprite#Effect? method returns true. Effects that will cause this to happen include damage resolution, flashing, battle animations, and collapsing.
Update
Arguments: None
Local Variables: None
How it Works: This is the frame update method for this class. First, the method sets the @battler instance variable for each of the Sprite_Battler objects representing the actors to the appropriate actor in $Game_Party.actors. The next part of the method checks to see if the battle background has changed as a result of a "Change Map Properties" event command. If it has, then the battle background's filename is updated to the one stored in $game_temp.battleback_name. The bitmap and the source rectangle for the battle background are then updated. The for sprite in @enemy_sprites + @actor_sprites loop performs the frame update method for each of the actor and monster sprites. The weather type is then updated if necessary. Each picture sprite and the timer sprite are updated. The @viewport1.tone = $game_screen.tone statement changes the tinting of viewport #1 to match the game screen's tone. The @viewport1.ox = $game_screen.shake statement causes viewport #1 to be displaced based on the magnitude of the screen shaking. The @viewport4.color = $game_screen.flash_color statement changes the color of viewport #4 to the color of any flash being performed on the screen. Viewports #1, #2, and #4 are then updated.
|
|