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
523
Reaction score
417
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 Profile Posts

I added footstep sounds to our content that I posted in a previous thread. I was unable to edit the post, so if you're interested, see below.

DOWNLOAD LINK

I've started working on rpg maker again, and I can see a lot of improvement from when I was 13. I still have a long way to go, but I'm proud that I've gotten this far.
Animated Title screen is by SharkerrBlue(SB)
I am using the Nightmare Land pack.
I just can't walk to the store for lunch without walking past people smoking. It not only smells bad, it's probably poisoning me. I'm afraid I'll eventually have to be hospitalized. I can't take another path because there's too much traffic and drivers in the plaza are reckless sometimes. I almost got run over once, even after looking both ways.
RyanYe wrote on whtdragon's profile.
Your art works about Wyrvens and Dragons are sooooooooo cooooooooool~! I like them so bad
Can you create more? like Archangels, Devils, Titans, Cyclops!!
My valentine cutscene is now available on itch.io and you can get the "source code" as well, feel free to check it out!

The game page on itch can be found at:

Forum statistics

Threads
108,796
Messages
1,039,550
Members
141,245
Latest member
feedtalefour
Top