Show Animation in a tile in front of the player?

Status
Not open for further replies.

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
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: 



Of course this will only affect specific animations, while on the map.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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?
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
It would have to be in every map unfortunately. Maybe something like an event spawner could be used?
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Thanks for moving it since it has come to this.

 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.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
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
 
Last edited by a moderator:

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
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
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
:)


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.
 
Last edited by a moderator:
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top