RMMV requestAnimation() unable to perform anime completely

henryandjay

Villager
Member
Joined
Jun 17, 2019
Messages
10
Reaction score
3
First Language
Chinese
Primarily Uses
RMMV
Hi all:

I am developing a game that the combat is directly performed on map. The player can see attack anime affect and damage, like the following image:
rpg_capture.png

Therefore, I got used of requestAnimation() function.
At the beginning, the animation works just fine, anime & sound effect can be performed entirely, which took about maybe 0.5 seconds to finish. However, due to a requirement that enemy movement phase may have to wait until another event finish, I refactor the mechanism to be asynchronous, using setTimeout() and function state, for pseudo code example:

Code:
toExecute = function() {
    let func = toExecute, waiting = 0;
    if (need to wait) {
        waiting = 50;
    } else {
        switch (global state) {
        case 0:
            // do something
            state = 1;
            break;
        case 1:
            // do something, state change to 2 if meet requirement
            xx.requestAnimation(yy);
            break;
        case 2:
            // return when meet condition, otherwise back to state 0
        }
    }
    setTimeout(func, waiting);
}
After the refactoring, game logic still works, but the animation will only remain very short time (maybe about 0.1 seconds), which makes both anime & sound effect seriously incomplete. In fact, sometimes the anime even not showed up.

I want to make the animation duration complete, also understanding what's happening. Can anyone help me with this?

BRs,
yuchieh
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,793
Reaction score
5,211
First Language
Dutch
Primarily Uses
RMXP

I've moved this thread to Learn Javascript. Please be sure to post your threads in the correct forum next time. Thank you.

 

henryandjay

Villager
Member
Joined
Jun 17, 2019
Messages
10
Reaction score
3
First Language
Chinese
Primarily Uses
RMMV
Really need help, any suggestions are welcomed!
 

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

Latest Threads

Latest Posts

Latest Profile Posts

A beloved family member passed away due to complication to combat COVID and diabetes. Rest in peace Grandma.
Just got FES pack for my MZ. The details of the tilesets and chars seem not very compatible with MZ rtp. Look like they are scaled up. Not saying it's bad, but just won't fit well.
I've been busy with other things lately but I'm getting back into working on stuff for my game next month. I think I'm going to fiddle with making NPC busts next, mixing and matching stuff from DLC I've purchased.
Just finished composing a boss battle theme!

Forum statistics

Threads
105,567
Messages
1,014,687
Members
137,239
Latest member
roeselerfinnole
Top