Jump to content

Stoping followcurve


Mehrdad
 Share

Recommended Posts

Hi everyone,

I'm new to pixi.js, I have made sprite and moving it by followcurve function, I want to detect mouse collision with sprite and change followcurve path, but I can't stop sprite and starting new path until the sprite reach to the end of current path.

xDestinition = yDestinition = 0;
function play() {    
    if (pointer.hitTestSprite(cat)) {
        console.log('*****************************************');
        gotoNewPath(cat);
    }
    z = Math.floor(giveMeDistance(cat.x, cat.y, xDestinition, yDestinition));
    if (z == 0) {
         gotoNewPath(cat);
    }
}
function gotoNewPath(movingObj, xD, yD, time) {
    xDestinition = (xD != null) ? xD : giveMeRand(fWidth);
    yDestinition = (yD != null) ? yD : giveMeRand(fHeight);
    let curve = [
        [movingObj.x, movingObj.y],
        [giveMeRand(fWidth), giveMeRand(fHeight)],
        [giveMeRand(fWidth), giveMeRand(fHeight)],
        [xDestinition, yDestinition]
    ];
    c.followCurve(
            movingObj,
            curve,
            120,
            "smoothstep",
            false
    );
}

Any advice?

thanks.

Link to comment
Share on other sites

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...