Skip to main content
edited body
Source Link
Valkea
  • 2.8k
  • 3
  • 18
  • 22

You could try something like the following code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
function downKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.UP )
    {
        isUp=true;
        character.gotoAndStop('up'); // up (animated?)
    }
    else if( event.keyCode == Keyboard.DOWN )
    {
        isUp=false;
        character.gotoAndStop('down'); // down (animated?)
    }
    
    else if( event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('left'); // (up)left
        else
            character.gotoAndStop('downleft'); // downleft      
    }
    else if( event.keyCode == Keyboard.RIGHT )
    {
        if( isUp )
            character.gotoAndStop('right'); // (up)right
        else
            character.gotoAndStop('downright'); // downright
    }
}

stage.addEventListener(KeyboardEvent.KEY_UP, upKey);
function upKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('up'); // up (still?)
        else
            character.gotoAndPlaygotoAndStop('down'); // down (still?)
    }
}

I tried to do something as close as possible to your original code.

But it's yet a very simple solution that doesn't handle multi-key pressed at the same time etc... And obviously you should consider different keyframes for immobile and animated "up" and "down". I supposed that your bools were globals so I reduced it to one because it doesn't seems useful in this portion of code, but indeed you can re-introduce the other bools if needed elsewhere.

You could try something like the following code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
function downKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.UP )
    {
        isUp=true;
        character.gotoAndStop('up'); // up (animated?)
    }
    else if( event.keyCode == Keyboard.DOWN )
    {
        isUp=false;
        character.gotoAndStop('down'); // down (animated?)
    }
    
    else if( event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('left'); // (up)left
        else
            character.gotoAndStop('downleft'); // downleft      
    }
    else if( event.keyCode == Keyboard.RIGHT )
    {
        if( isUp )
            character.gotoAndStop('right'); // (up)right
        else
            character.gotoAndStop('downright'); // downright
    }
}

stage.addEventListener(KeyboardEvent.KEY_UP, upKey);
function upKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('up'); // up (still?)
        else
            character.gotoAndPlay('down'); // down (still?)
    }
}

I tried to do something as close as possible to your original code.

But it's yet a very simple solution that doesn't handle multi-key pressed at the same time etc... And obviously you should consider different keyframes for immobile and animated "up" and "down". I supposed that your bools were globals so I reduced it to one because it doesn't seems useful in this portion of code, but indeed you can re-introduce the other bools if needed elsewhere.

You could try something like the following code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
function downKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.UP )
    {
        isUp=true;
        character.gotoAndStop('up'); // up (animated?)
    }
    else if( event.keyCode == Keyboard.DOWN )
    {
        isUp=false;
        character.gotoAndStop('down'); // down (animated?)
    }
    
    else if( event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('left'); // (up)left
        else
            character.gotoAndStop('downleft'); // downleft      
    }
    else if( event.keyCode == Keyboard.RIGHT )
    {
        if( isUp )
            character.gotoAndStop('right'); // (up)right
        else
            character.gotoAndStop('downright'); // downright
    }
}

stage.addEventListener(KeyboardEvent.KEY_UP, upKey);
function upKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('up'); // up (still?)
        else
            character.gotoAndStop('down'); // down (still?)
    }
}

I tried to do something as close as possible to your original code.

But it's yet a very simple solution that doesn't handle multi-key pressed at the same time etc... And obviously you should consider different keyframes for immobile and animated "up" and "down". I supposed that your bools were globals so I reduced it to one because it doesn't seems useful in this portion of code, but indeed you can re-introduce the other bools if needed elsewhere.

added 7 characters in body
Source Link
Valkea
  • 2.8k
  • 3
  • 18
  • 22

You could try something like the following code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
function downKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.UP )
    {
        isUp=true;
        character.gotoAndStop('up'); // up (animated?)
    }
    else if( event.keyCode == Keyboard.DOWN )
    {
        isUp=false;
        character.gotoAndStop('down'); // down (animated?)
    }
    
    else if( event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('left'); // (up)left
        else
            character.gotoAndStop('downleft'); // downleft      
    }
    else if( event.keyCode == Keyboard.RIGHT )
    {
        if( isUp )
            character.gotoAndStop('right'); // (up)right
        else
            character.gotoAndStop('downright'); // downright
    }
}

stage.addEventListener(KeyboardEvent.KEY_UP, upKey);
function upKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('up'); // up (fixstill?)
        else
            character.gotoAndPlay('down'); // down (fixstill?)
    }
}

I tried to do something as close as possible to your original code.

But it's yet a very simple solution that doesn't handle multi-key pressed at the same time etc... And obviously you should consider different keyframes for fixedimmobile and animated "up" and "down". I supposed that your bools were globals so I reduced it to one because it doesn't seems useful in this portion of code, but indeed you can re-introduce the other bools if needed elsewhere.

You could try something like the following code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
function downKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.UP )
    {
        isUp=true;
        character.gotoAndStop('up'); // up (animated?)
    }
    else if( event.keyCode == Keyboard.DOWN )
    {
        isUp=false;
        character.gotoAndStop('down'); // down (animated?)
    }
    
    else if( event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('left'); // (up)left
        else
            character.gotoAndStop('downleft'); // downleft      
    }
    else if( event.keyCode == Keyboard.RIGHT )
    {
        if( isUp )
            character.gotoAndStop('right'); // (up)right
        else
            character.gotoAndStop('downright'); // downright
    }
}

stage.addEventListener(KeyboardEvent.KEY_UP, upKey);
function upKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('up'); // up (fix?)
        else
            character.gotoAndPlay('down'); // down (fix?)
    }
}

I tried to do something as close as possible to your original code.

But it's yet a very simple solution that doesn't handle multi-key pressed at the same time etc... And obviously you should consider different keyframes for fixed and animated "up" and "down". I supposed that your bools were globals so I reduced it to one because it doesn't seems useful in this portion of code, but indeed you can re-introduce the other bools if needed elsewhere.

You could try something like the following code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
function downKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.UP )
    {
        isUp=true;
        character.gotoAndStop('up'); // up (animated?)
    }
    else if( event.keyCode == Keyboard.DOWN )
    {
        isUp=false;
        character.gotoAndStop('down'); // down (animated?)
    }
    
    else if( event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('left'); // (up)left
        else
            character.gotoAndStop('downleft'); // downleft      
    }
    else if( event.keyCode == Keyboard.RIGHT )
    {
        if( isUp )
            character.gotoAndStop('right'); // (up)right
        else
            character.gotoAndStop('downright'); // downright
    }
}

stage.addEventListener(KeyboardEvent.KEY_UP, upKey);
function upKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('up'); // up (still?)
        else
            character.gotoAndPlay('down'); // down (still?)
    }
}

I tried to do something as close as possible to your original code.

But it's yet a very simple solution that doesn't handle multi-key pressed at the same time etc... And obviously you should consider different keyframes for immobile and animated "up" and "down". I supposed that your bools were globals so I reduced it to one because it doesn't seems useful in this portion of code, but indeed you can re-introduce the other bools if needed elsewhere.

Post Undeleted by Valkea
Post Deleted by Valkea
Source Link
Valkea
  • 2.8k
  • 3
  • 18
  • 22

You could try something like the following code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
function downKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.UP )
    {
        isUp=true;
        character.gotoAndStop('up'); // up (animated?)
    }
    else if( event.keyCode == Keyboard.DOWN )
    {
        isUp=false;
        character.gotoAndStop('down'); // down (animated?)
    }
    
    else if( event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('left'); // (up)left
        else
            character.gotoAndStop('downleft'); // downleft      
    }
    else if( event.keyCode == Keyboard.RIGHT )
    {
        if( isUp )
            character.gotoAndStop('right'); // (up)right
        else
            character.gotoAndStop('downright'); // downright
    }
}

stage.addEventListener(KeyboardEvent.KEY_UP, upKey);
function upKey(event:KeyboardEvent)
{
    if( event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.LEFT )
    {
        if( isUp )
            character.gotoAndStop('up'); // up (fix?)
        else
            character.gotoAndPlay('down'); // down (fix?)
    }
}

I tried to do something as close as possible to your original code.

But it's yet a very simple solution that doesn't handle multi-key pressed at the same time etc... And obviously you should consider different keyframes for fixed and animated "up" and "down". I supposed that your bools were globals so I reduced it to one because it doesn't seems useful in this portion of code, but indeed you can re-introduce the other bools if needed elsewhere.