• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Orientation of the player

Contributor ,
Sep 10, 2013 Sep 10, 2013

Copy link to clipboard

Copied

I'm making a game and I've got my player who can go the right or to the left. The orientation of the player is defined in my Player class. The method gets called constantly while the player is in motion and it just switches the player’s orientation instantly when it needs to.

It works juste fine :

private function orientPlayer():void{

    // Make sure the player is pointed in the right direction

    if (xinc < 0 && scaleX > 0){

        scaleX = -scaleX;

    }

    if (xinc > 0 && scaleX < 0){

        scaleX = -scaleX;

    }

}

But, now I'm trying to put a transition between the "going right" and "going left" (create an animation of the turning side to side while moving).

I’ve created the turning-around animation for the character, and put that animation into a frame on the character’s main timeline with a frame name of “turn”, just like I've already have for “walk,” “talk”, and “grab.” In this movieclip I ve got an action placed on its final frame : stop(); dispatchEvent(new Event("clipFinished"));

Than I've changed my orientation method so that it stops the walking animation and movement, turns the character around, and then resumes the movement. It dit that :

private function orientPlayer():void{

// Make sure the player is pointed in the right direction

var dummyEvent:Event;

if (xinc < 0 && scaleX > 0){

stopWalking(dummyEvent);

gotoAndStop("turn");

// I have in my movie clip dispatch the "clipFinished" event

stageRef.addEventListener("clipFinished", resumeWalking);

}

if (xinc > 0 && scaleX < 0){

stopWalking(dummyEvent);

gotoAndStop("turn");

stageRef.addEventListener("clipFinished", resumeWalking);

}

}

And then I've added a resumeWalking method like so:

private function resumeWalking():void{

scaleX = -scaleX;

startWalking(targetX, targetY);

}

The problem : My player can now only go to the left. When I'm clicking to the right, my player goes to the frame "turn" and stays in this position... But If I'm clicking to the left, it's working (the "turn" position stops and he walks.)

Do you know why my player can only go to the left ?

Thank you !

TOPICS
ActionScript

Views

511

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2013 Sep 10, 2013

Copy link to clipboard

Copied

Use the trace function to see how the conditionals are getting processed.  The way you have that function written could be rewrtitten to one conditional since they both do the same thing.  You might need to figure out whether you want to go with scaleX versus -scaleX, and assign a value of 1 versus -1 instead of just changing it to be the opposite all the time.

private function orientPlayer():void{
    if ((xinc < 0 && scaleX > 0) || (xinc > 0 && scaleX < 0)){
        scaleX = -scaleX;
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 10, 2013 Sep 10, 2013

Copy link to clipboard

Copied

LATEST

Thanks ! It seems to work, but..

when I click on the right, the players goes to the frame "turn" and stays in it. Then if I click a second time, the player goes to the right.

Is there a way that he doesn't stop between the left and the right ?...(that when I click on the right it goes to the "turn" frame and directly to the "walk" frame ?)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines