RPG Maker
 

 Username:
 Password:
   Not a member? Register!

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.

Code


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

Properties


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.

Methods


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. 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

By continuing past this page, and by your continued use of this site, you agree to be bound by and abide by the Terms of Use.
©2004 - 2008 RPG RPG Revolution, All Rights Reserved. Contact Us · Privacy Policy · Legal Disclaimer
eXTReMe Tracker