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,818
Reaction score
5,213
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 Profile Posts

Evil7 added!


I did a bit of a remake on one of the maps, also I made a particle for jumping into the portal, and one for traveling through the portal. I'll probably add more sparkles later to embellish it. :LZSwink:
Polished the animation and added details :kaojoy:
Ami
What do you think about the Wood Bridge inside of Volcano?
Yet another gaming question, i'm currently playing Last of Us 2 and want to get another game to play next but can't decide between Ghost of Tsushima, Miles Morales & Jedi Fallen Order. After the latest mandalorian i AM on a star wars kick, but i also LOVED the last spiderman game that prequels Miles Morales. Ghost of Tsushima is the bottom of my list but i heard it was AWESOME. Just want a good story & fun gameplay.

Forum statistics

Threads
105,676
Messages
1,015,492
Members
137,353
Latest member
vongolavxv
Top