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,619
Reaction score
5,157
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

Yesterday I made my first step towards eating more healthily.
I saw candy on discount and did not buy it.
"They yearn for what they fear for."
I always told my DA fans how much I hate slot machines. They're fine in games as a risk-and-reward system. But when you're spending REAL MONEY in a Vegas casino to try and hit the jackpot (which very, very few people will), it can really hurt your budget. Gambling is a bad habit, and I don't like wasting my money on a slim chance. Go to Vegas for the experience, not the jackpot.
Took the kids to a corn maze. They gave us a map and had lights at certain points in the maze. Not overwhelming... or underwhelming... just... whelming.
Okay, vacuuming fruit flies out of the air is surprisingly effective.

Forum statistics

Threads
104,396
Messages
1,006,082
Members
135,927
Latest member
mich
Top