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,610
Reaction score
5,152
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

Its been almost 6 months since i've been here last and 5 years before that. the worst part is losing the game you were working on in a cpu fire.

Well time to go at it again.
my game is coming together im so happy
In this day and age, i might switch back to RMXP. I’ve lost faith in all the new plugins.
Wow it's been forever since I last logged in! I STILL want to make a game... I'll start it one day for sure!! It's a dream of mine.
This days I couldn't do anything... My mind is so confused and I couldn't work at all, I only wanted to play video games with my friends and that made all my projects delay a lot. Someone else feels this kind of thing sometimes? :/

Forum statistics

Threads
104,286
Messages
1,005,261
Members
135,797
Latest member
Famas
Top