Show Animation in a tile in front of the player?

● ARCHIVED · READ-ONLY
Started by kerbonklin 8 posts View original ↗
  1. Normally the Show Animation command must center-target either the player or an event in the current map. Is there a way I can instead play the animation on a tile directly in front of the player, depending on their direction?

    Example: 

    nWucjTc.png

    Of course this will only affect specific animations, while on the map.
  2. I would have a 'dummy' event and use the Set Event Location command to move it in front of the player, then play the animation over it.


    This is easy if you're only talking about this happening on one map - it would be a pain to have to create dummy events on a lot of maps for it.


    What a pity there's no note box on the animations tab.


    Would the 'dummy' event work for you?
  3. It would have to be in every map unfortunately. Maybe something like an event spawner could be used?
  4. I will see if I can do something here. How will you define where the animation goes - would you prefer to have a certain string in the animation name, or would you rather use a script call to run the animation, with an extra parameter specifying the offset?


    moving to RGSS3 Script Requests
  5. Thanks for moving it since it has come to this.

    Shaz said:
     would you rather use a script call to run the animation, with an extra parameter specifying the offset?
    This sounds like the better implementation, as long as the offset is based on direction as well.

    eg:

    If direction == 6 then +32 x offset

    If direction == 4 then -32 x offset

    If direction == 8 then +32 y offset

    If direction == 2 then -32 y offset

    Edit: Or I could ways check the player direction before running the animation, using 4 conditional branches, and then apply the proper offset parameter of yours. Your choice on that part.
  6. Okay, here's the script.

    To use it, make any of the following calls from the Call Script event command

    Code:
    $game_player.play_offset_animation(id, offset)$game_map.events[id].play_offset_animation(id, offset)
    or the following call from the Script button in a Set Move Route event (to play the animation on the target of the move route)
    Code:
    play_offset_animation(id, offset)
    Valid values for 'offset' are:
    Code:
    First group ignores character's direction :over - play animation on the character (this is the default, and the way animations currently play):above - play animation on the tile above the character:below - play animation on the tile below the character:left - play animation on the tile left of the character :right - play animation on the tile right of the characterSecond group is based on character's direction:front - play animation on the tile in front of the character:back - play animation on the tile behind the character:charleft - play animation on the tile to the character's left:charright - play animation on the tile to the character's right
    Note - this sets the STARTING tile for the animation. If the character walks around, the animation will move with him. But if the character changes direction while the animation is playing, the animation won't spin around accordingly. So if your character is facing down and you tell it to show an animation in front of the character, then you make your character turn around, the animation will continue to play on the tile below the character. It will not move so it is always in front.
    Spoiler
    Code:
    #========================================================================# OFFSET ANIMATIONS# Version 1.0# Author: Shaz#------------------------------------------------------------------------# DESCRIPTION# Allows you to set an animation to play on a tile next to the character,# rather than right over it#------------------------------------------------------------------------# TO INSTALL# Copy and paste into a new slot in Materials.# This script aliases the following methods, and should be placed # below any other scripts that overwrite them:#   Game_CharacterBase.init_public_members#   Sprite_Base.initialize#   Sprite_Base.start_animation#   Sprite_Character.setup_new_effect# This script overwrites the following method, and should be placed above# any other scripts that alias the same:#   Sprite_Base.animation_set_sprites# No customization necessary.#------------------------------------------------------------------------# TO USE# Call the method play_offset_animation(anim_id[, offset]) on the character# (which could be the player, a follower, a vehicle or an event) to start# the animation in a location other than over the character.# Call the method cancel_offset_animation to cancel it, so the next animation# will not be played with the same offset# # Valid values:# - the following values do not take the player's facing direction into account# :over        (default - play animation on the character)# :above       (play animation on the tile above the character)# :below       (play animation on the tile below the character)# :left        (play animation on the tile to the left of the character)# :right       (play animation on the tile to the right of the character)# - the following values DO take the player's facing direction into account# :front       (play animation on the tile in front of the character)# :back        (play animation on the tile behind the character)# :charleft    (play animation on the tile to the character's left)# :charright   (play animation on the tile to the character's right)#------------------------------------------------------------------------# WARNINGS# This script will NOT move around if the character changes direction while the #  animation is playing (so if you set a long animation to play in front#  of the character, and make the character turn around, the animation will#  continue playing where it started.#------------------------------------------------------------------------# EXAMPLES# $game_player.play_offset_animation(10, :above)# $game_map.events[8].play_offset_animation(10, :front)#========================================================================class Game_CharacterBase  attr_reader    :anim_offset             # animation offset    alias shaz_oa_init_public_members init_public_members  def init_public_members    shaz_oa_init_public_members    @anim_offset = :over  end  def play_offset_animation(anim_id, offset = :over)    @anim_offset = offset    @animation_id = anim_id  end  def cancel_offset_animation    @anim_offset = :over  endend#==============================================================================# ** Sprite_Base#------------------------------------------------------------------------------#  A sprite class with animation display processing added.#==============================================================================class Sprite_Base < Sprite  attr_accessor        :anim_offset  attr_accessor        :char_dir  #--------------------------------------------------------------------------  # * Object Initialization  #--------------------------------------------------------------------------  alias shaz_oa_initialize initialize  def initialize(viewport = nil)    shaz_oa_initialize(viewport)    @anim_offset = :over    @char_dir = 0  end  #--------------------------------------------------------------------------  # * Start Animation  #--------------------------------------------------------------------------  alias shaz_oa_start_animation start_animation  def start_animation(animation, mirror = false)    @offset_ox = 0    @offset_oy = 0    shaz_oa_start_animation(animation, mirror)    if @animation      setup_animation_offset if @anim_offset != :over    end  end  #--------------------------------------------------------------------------  # * Offset Animation to Another Tile  #--------------------------------------------------------------------------  def setup_animation_offset    case @anim_offset    when :left; @offset_ox -= 32    when :right; @offset_ox += 32    when :above; @offset_oy -= 32    when :below; @offset_oy += 32    when :front      case @char_dir      when 2; @offset_oy += 32      when 4; @offset_ox -= 32      when 6; @offset_ox += 32      when 8; @offset_oy -= 32      end    when :back      case @char_dir      when 2; @offset_oy -= 32      when 4; @offset_ox += 32      when 6; @offset_ox -= 32      when 8; @offset_oy += 32      end    when :charleft      case @char_dir      when 2; @offset_ox += 32      when 4; @offset_oy += 32      when 6; @offset_oy -= 32      when 8; @offset_ox -= 32      end    when :charright      case @char_dir      when 2; @offset_ox -= 32      when 4; @offset_oy -= 32      when 6; @offset_oy += 32      when 8; @offset_ox += 32      end    end  end    #--------------------------------------------------------------------------  # * Set Animation Sprite  #     frame : Frame data (RPG::Animation::Frame)  #--------------------------------------------------------------------------  def animation_set_sprites(frame)    cell_data = frame.cell_data    @ani_sprites.each_with_index do |sprite, i|      next unless sprite      pattern = cell_data[i, 0]      if !pattern || pattern < 0        sprite.visible = false        next      end      sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2      sprite.visible = true      sprite.src_rect.set(pattern % 5 * 192,        pattern % 100 / 5 * 192, 192, 192)      if @ani_mirror        sprite.x = @ani_ox - cell_data[i, 1] + @offset_ox        sprite.y = @ani_oy + cell_data[i, 2] + @offset_oy        sprite.angle = (360 - cell_data[i, 4])        sprite.mirror = (cell_data[i, 5] == 0)      else        sprite.x = @ani_ox + cell_data[i, 1] + @offset_ox        sprite.y = @ani_oy + cell_data[i, 2] + @offset_oy        sprite.angle = cell_data[i, 4]        sprite.mirror = (cell_data[i, 5] == 1)      end      sprite.z = self.z + 300 + i      sprite.ox = 96      sprite.oy = 96      sprite.zoom_x = cell_data[i, 3] / 100.0      sprite.zoom_y = cell_data[i, 3] / 100.0      sprite.opacity = cell_data[i, 6] * self.opacity / 255.0      sprite.blend_type = cell_data[i, 7]    end  endendclass Sprite_Character < Sprite_Base  alias shaz_oa_setup_new_effect setup_new_effect  def setup_new_effect    @anim_offset = @character.anim_offset    @char_dir = @character.direction    shaz_oa_setup_new_effect  endend
  7. Amazing work, Shaz!  I shall give it a go right now and tell you how it goes. The whole "animation not flipping if you change directions" part is fine, I wouldn't like it honestly if it did so. It would look ugly with my Field skills.

    *Goes to test*

    Edit: It works amazingly! You're a savior to my project's Field Skill aesthetics, lol. =P
  8. :)


    remember you'll need to call cancel_offset_animation if you just want to play a regular animation over the same character/event later - if that's not called, any future animations will also play using the same offset.


    Maybe I should see if I can do that by default when the animation ends ...


    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.