Checking which frame of a character sheet is currently active

modelarious

Warper
Member
Joined
Oct 11, 2019
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMMV
I have a character sheet for the player that triggers when they are idle for a while. The sheet has them going from standing to laying down in 6 frames, sleeping for 3 frames and then standing back up in 7 frames.

I'm looking to pause the animation when it reaches the 9th frame without using timers (as the character sheet may change in the future). Is there a function that will let me query which animation frame is currently being displayed?

Alternatively, is there a way to know if a character sheet has reached the last frame and is about to return to the first frame? I need to know when this animation has finished a cycle so I can smoothly transition back into the walking animation.

6niMk.png
 
Last edited:

Restart

Veteran
Veteran
Joined
Mar 15, 2019
Messages
526
Reaction score
418
First Language
English
Primarily Uses
RMMV
Are you using a premade plugin for the idle poses (like mog's) or rolling your own?

Anyway, what you're looking for is the ._pattern variable attached to a character.

Here's the code that increments it in rpg_objects
Code:
Game_CharacterBase.prototype.updatePattern = function() {
    if (!this.hasStepAnime() && this._stopCount > 0) {
        this.resetPattern();
    } else {
        this._pattern = (this._pattern + 1) % this.maxPattern();
    }
};

Game_CharacterBase.prototype.maxPattern = function() {
    return 4;
};

Game_CharacterBase.prototype.pattern = function() {
    return this._pattern < 3 ? this._pattern : 1;
};

Game_CharacterBase.prototype.setPattern = function(pattern) {
    this._pattern = pattern;
};

Game_CharacterBase.prototype.isOriginalPattern = function() {
    return this.pattern() === 1;
};

Game_CharacterBase.prototype.resetPattern = function() {
    this.setPattern(1);
};


And here's some of the code modifying it in MOG_CharPoses
Code:
//==============================
// * Pattern
//==============================
Game_CharacterBase.prototype.pattern = function() {
   var pattern = this._frames.enabled ? [this._frames.max,0] : [3,1];
    return this._pattern < pattern[0] ? this._pattern : pattern[1];
};

//==============================
// * reset Pattern
//==============================
Game_CharacterBase.prototype.resetPattern = function() {
   var initPattern = this._frames.enabled ? 0 : 1;
    this.setPattern(initPattern);
};

//==============================
// * update Pattern Poses
//==============================
Game_CharacterBase.prototype.maxPattern = function() {
   var maxPattern = this._frames.enabled ? this._frames.max: 4;
    return maxPattern;
};

//==============================
// * update Animation Count
//==============================
var _mog_charPose_charBase_updateAnimationCount = Game_CharacterBase.prototype.updateAnimationCount;
Game_CharacterBase.prototype.updateAnimationCount = function() {
   _mog_charPose_charBase_updateAnimationCount.call(this);
    this._animationCount += this._frames.speed;
};

I don't recall of any built-in function that lets you freeze something at the current pattern, but it should be pretty easy to add an attribute and check it in the pattern update function.
 

modelarious

Warper
Member
Joined
Oct 11, 2019
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMMV
That's very helpful, thanks for the thorough reply!

I'm extending Modern Algebra's ExtraMovementFrames plugin, so the solution ended up being to capture the output of this:

```
var patternIndex = (this._pattern % this.emfCharacterState().pattern.length);
```

which uses the `._pattern` property you mentioned, modulo the length of the animation.

I then used `this.setStepAnime(false);` to pause the walking animation of the character once it reached the desired frame.
 

MrNybbles

Veteran
Veteran
Joined
Nov 6, 2019
Messages
59
Reaction score
31
First Language
English
Primarily Uses
RMMV
Alternatively, is there a way to know if a character sheet has reached the last frame and is about to return to the first frame?

The way animation works it loops between the first and last frame. Probably the best way to do this would be:

1) Call Sprite_Character._character.direction() to get the direction (2, 4, 6, 8) so you know what frame to look for.
2) Get the current frame (AKA pattern) from Sprite_Character._pattern.

Sprite Sheet Frame Layout Example:

0 1 2 -- Facing down, Direction 2
3 4 5 -- Facing Left, Direction 4
6 7 8 -- Facing Right, Direction 6
9 A B -- Facing Up, Direction 8
Note: Frames in the middle column are used for when the character is idle.

For Sprite_Character._pattern moving Right would look like: 1 2 0 1 2 0 1 2 0. . .
because it is an index into the row (and each row is an animation sequence).

I wrote a plug-in a while ago to extend how the animation sequences work. It doesn't do what you want, but it is under the MIT License so this might be a good place to start. I wrote it specifically to handle the 8-direction CPACK sprites, but 8-directional input will work with 4-direction sprites as well.

https://github.com/MrNybbles/RPG-Maker-MV/blob/master/nyb_SpriteExt.js

EDIT:
For some reason I was thinking of how the battlers animate, the screen sprites just loop.
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

Barthdry wrote on tln143's profile.
Hello tln143 Welcome to the RPG Maker Forum. We wish you enjoy and make good rpg games
Barthdry wrote on 00cassiesmells's profile.
Hello 00casiemells Welcome to the RPG Maker Forum. We wish you enjoy and make good rpg games
Remember guys: Drink water and workout is important too! Don't stay too much time on the PC working! :D
Ami
--- Quest For Female ---

Guild Leader: Ladies,you got a Job for today. You have to Battle with Marauder,only Female must to this Job.
F.Magic Knight: So,only Female can do this?
Heroine: I can't wait for this!
Gunner Lady: Well,i can use the Seduction Skill to them,It's effective for Male Target
F.Knight: You always use that?
RPG Maker MZ just crashed, please tell me I didn't just lose 4 hours of progress.

Forum statistics

Threads
109,034
Messages
1,041,463
Members
141,516
Latest member
00cassiesmells
Top