Jump to content

Pixi gotoAndPlay() doesn't work


jakubdev
 Share

Recommended Posts

Hello,

As once played AnimatedSprite stop on penultimate frame and i want to use same AnimatedSprite from start on another round to safe some lines, but when i use gotoAndPlay(0) it just plays one frame and stops also adding play() afterwards doesn't help.

 

There aren't any errors catch'ed and I couln't find something special on profiler ,but I'm quite bad at it. 

export const attackEnemy = (playerTurn, enemyTurn, app, delta) => {
    return new Promise((resolve, reject) => {
        try {
            const [playerTurnIdleSprite, playerTurnCurrentSprite,
                enemyIdleCurrentSprite, enemyTurnCurrentSprite] = getBattleSprites(playerTurn, enemyTurn)
            const {playerOne, playerTwo} = getPlayersPositions(playerTurnIdleSprite, enemyTurnCurrentSprite);

            // To be replaced
            const dumbFunction = () => {
                if (!firstStep && playerTurnIdleSprite.x >= -playerTwo.x) {
                    playerTurnIdleSprite.x -= 2 * delta

                    if (playerTurnIdleSprite.y >= playerTwo.y) {
                        playerTurnIdleSprite.y -= 2 * delta;
                        playerTurnCurrentSprite.y = playerTurnIdleSprite.y;
                    }

                } else if (!firstStep) {
                    playerTurnCurrentSprite.x = playerTurnIdleSprite.x
                    playerTurnIdleSprite.visible = false;
                    playerTurnCurrentSprite.visible = true;
                    playerTurnCurrentSprite.gotoAndPlay(0);
                    enemyIdleCurrentSprite.visible = false;
                    enemyTurnCurrentSprite.visible = true;
                    enemyTurnCurrentSprite.gotoAndPlay(0);
                }

                playerTurnCurrentSprite.onComplete = () => {
                    firstStep = true;
                    playerTurnIdleSprite.visible = true;
                    playerTurnIdleSprite.play();
                    playerTurnCurrentSprite.visible = false;
                    enemyIdleCurrentSprite.visible = true;
                    enemyIdleCurrentSprite.play();
                    enemyTurnCurrentSprite.visible = false;
                }

                if (firstStep && playerTurnIdleSprite.x <= playerOne.x) {
                    playerTurnIdleSprite.x += 2 * delta
                    if (playerTurnIdleSprite.x > playerOne.x) {
                        playerTurnIdleSprite.x = playerOne.x;
                        app.ticker.remove(dumbFunction, dumbFunction);
                        firstStep = false;
                        resolve('success');
                    }
                }
            }
            app.ticker.add(dumbFunction, dumbFunction)
        } catch
            (e) {
            console.log(e);
            reject(e);
        }
    })
}

 

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...