Battle - Shake Screen when playing frames of animation

Panda_Artist

Humble RPG Fan
Veteran
Joined
Dec 22, 2018
Messages
192
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
Good Morning / Day / Afternoon / Evening everyone.

I have a request for a certain kind of snippet

So I would like the following:

1. The ability to make the battle screen shake during selected frames of animation

If this isn't too difficult I would really appreciate the help
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
647
Reaction score
423
First Language
English
Primarily Uses
RMVXA
Here you go:
Ruby:
=begin
#==============================================================================#
#   AMN Animation Shake
#   Version   1.02
#   Author:   AMoonlessNight
#   Date:     04 Jul 2020
#   Latest:   05 Jul 2020
#==============================================================================#
#   UPDATE LOG
#------------------------------------------------------------------------------#
# 04 Jul 2020 - created the script
# 05 Jul 2020 - fixed bug with frame ID, made compatible with TheoAllen's 
#               Multiple Animations script
#==============================================================================#
#   TERMS OF USE
#------------------------------------------------------------------------------#
# - Please credit AMoonlessNight or A-Moonless-Night
# - Free for non-commercial use; contact for commercial use
# - If you would like to edit/adjust this script, please make edits as a new
#   script (do not edit this script directly) and provide proper credit
# - I'd love to see your game if you end up using one of my scripts
#==============================================================================#

This script makes it so that you can set the screen to shake during certain
frames of an animation.

=end
module AMN_Animations
  SHAKE = {}
#==============================================================================
# ** EDITABLE REGION BELOW
#------------------------------------------------------------------------------
#  Change the values in the area below to suit your needs.
#==============================================================================

# SHAKE[ANIMATION_ID] = {
#   FRAME_ID => [POWER, SPEED, DURATION],
# }

  SHAKE[1] = {
  # FRAME_ID => [POWER, SPEED, DURATION],
    2 => [4, 4, 10],
  }
  
  SHAKE[68] = {
  # FRAME_ID => [POWER, SPEED, DURATION],
    3 => [8, 8, 10],
  }
  
  
#==============================================================================
# ** END OF EDITABLE REGION
#------------------------------------------------------------------------------
#  Please do not edit below this point unless you know what you are doing.
#==============================================================================

end

class RPG::Animation
  include AMN_Animations
  
  def init_animation_shake_timings
    @timings.each { |timing| timing.init_shake_timings }
    if SHAKE.key?(@id)
      SHAKE[@id].each do |frame_id, shake_array|
        timing = RPG::Animation::Timing.new
        timing.shake_power = [[shake_array[0], 9].min, 0].max
        timing.shake_speed = [[shake_array[1], 9].min, 0].max
        timing.shake_duration = shake_array[2]
        timing.frame = frame_id
        @timings << timing
        @timings.sort_by! { |timing| timing.frame }
      end
    end
  end

end

class RPG::Animation::Timing
  attr_accessor :shake_power, :shake_speed, :shake_duration

  def init_shake_timings
    @shake_power = 0
    @shake_speed = 0
    @shake_duration = 0
  end

end

module DataManager
  class << self; alias :amn_anishake_datamgr_loaddb :load_database; end

  def self.load_database
    amn_anishake_datamgr_loaddb
    init_animation_shake_timings
  end
  
  def self.init_animation_shake_timings
    $data_animations.each { |obj| obj.init_animation_shake_timings unless obj.nil? }
  end
  
end

class Sprite_Base < Sprite
  
  def animation_process_shake(timing)
    if timing.shake_power > 0 && timing.shake_speed > 0 && !@ani_duplicated
      screen = $game_party.in_battle ? $game_troop.screen : $game_map.screen
      screen.start_shake(timing.shake_power, timing.shake_speed, timing.shake_duration)
    end
  end
  
  alias amn_anishake_spritebase_aniproctiming animation_process_timing
  def animation_process_timing(timing)
    amn_anishake_spritebase_aniproctiming(timing)
    animation_process_shake(timing) unless $imported && $imported[:Theo_MultiAnime]
  end
  
end

if $imported && $imported[:Theo_MultiAnime]
  class Sprite_MultiAnime < Sprite_Base
    
    alias amn_anishake_spritemultanim_aniproctiming animation_process_timing
    def animation_process_timing(timing)
      animation_process_shake(timing)
      amn_anishake_spritemultanim_aniproctiming(timing)
    end
    
  end
end

EDIT: updated code
 
Last edited:

Panda_Artist

Humble RPG Fan
Veteran
Joined
Dec 22, 2018
Messages
192
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
animation shake.png

I am NOT properly doing something correctly or maybe I have a script that is making this incompatible

I'm using TheoAllen's multiple animations also, in conjunction with your other Z animation script... maybe there is an incompatibility

Unfortunately it doesn't seem to work, I code the animation id and the frames, but in game, the shake effect ALWAYS only happens when the animation starts... maybe it's one of the scripts i'm using....

EDIT:

Nope, it doesn't seem to work in a new clean project either, no matter which frame I code it in, the shake effect always starts in the first frame for some reason.

Is there anything here I am not doing right?
 
Last edited:

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,402
Reaction score
499
First Language
English
Primarily Uses
RMVXA
You have animations that have 118 frames? that's a long animation.
 

Panda_Artist

Humble RPG Fan
Veteran
Joined
Dec 22, 2018
Messages
192
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
Yeah some abilities I have have some big animations.

Unfortunately this snippet doesn't seem to work in a new clean project either, no matter which frame I code it in, the shake effect always starts in the first frame for some reason.

Is there anything here I am not doing right?
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
647
Reaction score
423
First Language
English
Primarily Uses
RMVXA
Updated the original. Forgot to add something in about the frame ID, so this version should work now, and should work with Theo's script (although I haven't tested extensively).
 

Panda_Artist

Humble RPG Fan
Veteran
Joined
Dec 22, 2018
Messages
192
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
After testing it:

YES. So far so good and it works perfectly so far.

I will let you know if I encounter any errors, but amazing job and thank you very much for this!!
 

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

Latest Threads

Latest Profile Posts

So I just spent the weekend...playing my own game. The one I released last year. Yep you heard that right.
Goal for MZ? None... I'm still curious how to finish my VXA project and how it looks like when it actually finished. Which will take at least another two years. Coming late again to the party.
Finding it amusing that people are posting support questions in new threads for an engine that isn't even released yet. Touch and Archeia are the only ones authorised to say anything, and there's only one active thread where they'll be answering questions.
I think my goal for MZ ... is to actually release a game and not have twenty technical demos and debugging projects. Let's see if I can manage that. ;o
I am starting to enjoy writing. I never thought I would enjoy it since my dyslexia was holding me back so much.
Thanks to the community here :)
For those interested chapter 2 and 3 are available to read here:

Forum statistics

Threads
100,652
Messages
978,096
Members
132,261
Latest member
DarthNinjus
Top