#=============================================== # Moshroom's 8-frame animation v. 0.1 # 28.5.2015 # # How to use: # 1) Copy above main # 2) Use charactersets with 8-frame animation #=============================================== #============================================================================== # ** Sprite_Character #------------------------------------------------------------------------------ # This sprite is used to display the character.It observes the Game_Character # class and automatically changes sprite conditions. #============================================================================== class Game_Character #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update # Branch with jumping, moving, and stopping if jumping? update_jump elsif moving? update_move else update_stop end # If animation count exceeds maximum value # * Maximum value is move speed * 1 taken from basic value 18 if @anime_count > 18 - @move_speed * 2 # If stop animation is OFF when stopping if not @step_anime and @stop_count > 0 # Return to original pattern @pattern = @original_pattern # If stop animation is ON when moving else # Update pattern @pattern = (@pattern + 1) % 8 ### This is where the magic happens end # Clear animation count @anime_count = 0 end # If waiting if @wait_count > 0 # Reduce wait count @wait_count -= 1 return end # If move route is forced if @move_route_forcing # Custom move move_type_custom return end # When waiting for event execution or locked if @starting or lock? # Not moving by self return end # If stop count exceeds a certain value (computed from move frequency) if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency) # Branch by move type case @move_type when 1 # Random move_type_random when 2 # Approach move_type_toward_player when 3 # Custom move_type_custom end end end end class Sprite_Character < RPG::Sprite #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :character # character #-------------------------------------------------------------------------- # * Object Initialization # viewport : viewport # character : character (Game_Character) #-------------------------------------------------------------------------- def initialize(viewport, character = nil) super(viewport) @character = character update end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super # If tile ID, file name, or hue are different from current ones if @tile_id != @character.tile_id or @character_name != @character.character_name or @character_hue != @character.character_hue # Remember tile ID, file name, and hue @tile_id = @character.tile_id @character_name = @character.character_name @character_hue = @character.character_hue # If tile ID value is valid 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 # If tile ID value is invalid else self.bitmap = RPG::Cache.character(@character.character_name, @character.character_hue) @cw = bitmap.width / 8 ### This is where the magic happens @ch = bitmap.height / 4 self.ox = @cw / 2 self.oy = @ch end end # Set visible situation self.visible = (not @character.transparent) # If graphic is character if @tile_id == 0 # Set rectangular transfer sx = @character.pattern * @cw sy = (@character.direction - 2) / 2 * @ch self.src_rect.set(sx, sy, @cw, @ch) end # Set sprite coordinates self.x = @character.screen_x self.y = @character.screen_y self.z = @character.screen_z(@ch) # Set opacity level, blend method, and bush depth self.opacity = @character.opacity self.blend_type = @character.blend_type self.bush_depth = @character.bush_depth # Animation if @character.animation_id != 0 animation = $data_animations[@character.animation_id] animation(animation, true) @character.animation_id = 0 end end end #============================================================================== # ** Window_Base #------------------------------------------------------------------------------ # This class is for all in-game windows. #============================================================================== class Window_Base < Window #-------------------------------------------------------------------------- # * Draw Graphic # actor : actor # x : draw spot x-coordinate # y : draw spot y-coordinate #-------------------------------------------------------------------------- def draw_actor_graphic(actor, x, y) bitmap = RPG::Cache.character(actor.character_name, actor.character_hue) cw = bitmap.width / 8 ### This is where the magic happens ch = bitmap.height / 4 src_rect = Rect.new(0, 0, cw, ch) self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect) end end