4 way movement not working

MajorH

  • Posts: 1
Hello, I'm decently new to stencyl and have already encountered a problem. When I try to use 4 way movement , something strage occurs, but i'll try to explain it to my best ability

Once I start to test the game(in flash player) I am able to move left and right at the speed i've chosen, however, once i press the up or down key,  i end up going extremely slow when pressing left or right again, and when i do press up or down, it doesn't end up working at all.

i've made sure the coding is correct and my behavior is connected to my Actor, here is my coding in script form:

class Design_5_5_CharMovement extends ActorScript
{
   public var _CharSpeed:Float;
   
   
   public function new(dummy:Int, actor:Actor, dummy2:Engine)
   {
      super(actor);
      nameMap.set("Actor", "actor");
      nameMap.set("Char Speed", "_CharSpeed");
      _CharSpeed = 0.0;
      
   }
   
   override public function init()
   {
      
      /* ======================== When Updating ========================= */
      addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
      {
         if(wrapper.enabled)
         {
            if(isKeyDown("up"))
            {
               actor.setXVelocity(0);
               actor.setYVelocity((_CharSpeed - (_CharSpeed * 2)));
            }
            else if(isKeyDown("down"))
            {
               actor.setXVelocity(0);
               actor.setYVelocity(_CharSpeed);
            }
            else if(isKeyDown("left"))
            {
               actor.setXVelocity((_CharSpeed - (_CharSpeed * 2)));
               actor.setYVelocity(0);
            }
            else if(isKeyDown("right"))
            {
               actor.setXVelocity(_CharSpeed);
               actor.setYVelocity(0);
            }
            else
            {
               actor.setXVelocity(0);
               actor.setYVelocity(0);
            }
         }
      });
      
   }
   
   override public function forwardMessage(msg:String)
   {
      
   }


Just so you know "Char_speed" is an attribute i created.

Any help????/

mpeterskc

  • Posts: 22
Please try using the "Take Screenshot" feature to post a screenshot of your code in block form. It will be easier for most users to read. From the way you described your problem I'm wondering if somewhere your "Char_speed" attribute is being unintentionally set to a lower number.