Referencing a Single Frame of an Animation

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
(Posting it here as I think it's a safe bet.)

Hello! I'm attempting to tie in a sound effect to an animation I've made, so it plays during the corresponding frame. This is possible in the database, where you can set up these animations to have sound effects included. So, how would I go about doing this for, say, a walking animation?
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,635
Reaction score
5,116
First Language
English
Primarily Uses
RMVXA
The frames of a Character/Event model's animation are known as "pattern" in Ace's code. So inside the class, you could reference it with:
Code:
@pattern
So you can use that inside the class, or outside the class (that is, anywhere else in the code or the game) you would use xxx.pattern where xxx is the reference to a Character/Event, such as $game_player.pattern or $game_map.events[21].pattern

I believe that Pattern is not zero-indexed and the three patterns (frames) of a model will be numbered as 1, 2, and 3.

As far as playing a certain SE whenever an event hits a certain frame of their pattern, I suppose you could either run a parallel event (or add a method to Game_Map's update method) to continually check whether a certain event is currently displaying in a specific pattern (frame). Or, you could do a search for where pattern is already being manipulated in Ace's default code, and add in a SE there.
 
Last edited:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
@Wavelength To get the format right, I suggest you use the 'Code' option from the Insert icon and put it in there, as that is the only way of preventing the forum software from auto formatting.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,635
Reaction score
5,116
First Language
English
Primarily Uses
RMVXA
Thanks for the tip, @Kes! Edited my post accordingly to use the code formatting, to prevent the @ sign from creating a member tag. :)
 

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Thank you both! I'm going to alias the code for when the player walks to add a sound effect for a footstep, and cannibalize some code from another script to variate the pitch so it's not the same sound over and over. Is there a way to check the file name of the spritesheet, while we're at it?

Edit: I think I'm doing this wrong. I'm just doing an if branch right now to test out the syntax, so I put:

Code:
alias game_characterbase_move_straight_cxj_fm move_straight
  def move_straight(d, turn_ok = true)
    if $game_map.free_movement_enabled?
      if $game_map.events[-1].@pattern == 2
      pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
      @move_poll+= [[d, turn_ok]] * (distance_per_frame / pixelstep).ceil
      end
    else
      game_characterbase_move_straight_cxj_fm(d, turn_ok)
    end
  end
I also tried:

Code:
 alias game_characterbase_move_straight_cxj_fm move_straight
  def move_straight(d, turn_ok = true)
    if $game_map.free_movement_enabled?
      if $game_map.events[-1].@pattern(2) == true
      pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
      @move_poll+= [[d, turn_ok]] * (distance_per_frame / pixelstep).ceil
      end
    else
      game_characterbase_move_straight_cxj_fm(d, turn_ok)
    end
  end
Edit 2: No matter how I type it, 'literallyanything'.pattern results in a NoMethodError for pattern.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
You are editing a game_characterbase method, so you don't need to use $game_map.events to get the event. this is the event (assuming you are wanting to check the same event that's doing the moving).

So just use
Code:
@pattern
I think it actually is zero-indexed, and it moves in 0-1-2-1-0-1-2... but I'm at work & don't have access to my computer to check. The middle one is the 'idle' sprite.
 

Robert-Character Creator

Waiting for Replies
Veteran
Joined
Feb 8, 2014
Messages
518
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Hmm, I also have a script that modifies the number of frames in a sprite, and I use 8. Do you think it would work the same way, but with 1-8, or 0-7, as the case may be?
 

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

Latest Threads

Latest Posts

Latest Profile Posts

He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!

Forum statistics

Threads
106,036
Messages
1,018,461
Members
137,821
Latest member
Capterson
Top