RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Sprite_Character

Sprite_Character


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.

Code


class Sprite_Character < RPG::Sprite
# ------------------------------------
 attr_accessor :character
# ------------------------------------
  def initialize(viewport, character = nil)
    super(viewport)
    @character = character
    update
  end
# ------------------------------------
  def update
    super
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
        @ch = bitmap.height / 4
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
    self.visible = (not @character.transparent)
    if @tile_id == 0
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end

Properties


Character: The Game_Character object this sprite represents.

Tile_ID: If the character's graphic is drawn from a tileset rather than a character set file, then this value is set to the ID of that tile.

Character_Name: The filename of the character graphic.

Character_Hue: The character sprite's hue modification value.

CW: The width of the character graphic, in pixels.

CH: The height of the character graphic, in pixels.

Methods


Initialize

Arguments: None
Local Variables: None

How it Works: This method sets the character to which the sprite belongs and updates the character so that all the other instances variables are initialized to their proper values immediately.

Update

Arguments: None
Local Variables: None

How it Works: This method updates the character sprite each frame. First, the call to super does the updating that is common to all sprites. Then, the method checks to see if the value of @tile_id differs from the character's old tile ID ,the value of @character_name differs from from the character's old filename, or the value of @character_hue differs from the character's old hue modification due to a "Move Event" command changing these values. If any of these is true, then the values of @tile_id, @character_name, and @character_hue are all updated to reflect the character's new settings. If the tile ID is 384 or more (a valid tile), then the character's graphic is changed to this new tile. Otherwise, the character's graphic is changed to the appropriate character set file. Next the character is set to be visible, as long as it isn't transparent. A little explanation is in order to understand the if @tile_id == 0 clause. This means that the character is being drawn from a character set file. To begin, all sixteen patterns are shown, but the viewport size is manipulated so that only one pattern at a time shows up. The sx = @character.pattern * @cw statement displaces the viewport to the right within the character set file by an amount equal to the width of one pattern, times the pattern number being shown, with 0 being the first pattern. The sy = (@character.direction - 2) / 2 * @ch statement displaces the viewport downward based on the character's facing (2 = Down, 4 = Left, 6 = Right, 8 = Up). The self.src_rect.set(sx, sy, @cw, @ch) statement then sets up the slice of the character set file you see based on these displacements. The next three statements set the character's X, Y, and Z coordinates on the screen. Then, the character opacity, blending, and obscurement are set based on the current values for that character. Finally, if there's an animation waiting to resolve on this character, then the animation is played and the value of @character.animation_id is reset to 0. 
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.

RPG RPG Revolution is an Privacy Policy and Legal