Movement with arrow keys or WASD

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Movement with arrow keys or WASD

Postby rjgtav » 11 Jun 2009, 17:10

Hi there. I am having problems with the avatar chat. I want to move the character with the arrow keys or with WASD but nothing works. If i test the original example with the mouse, it works. Please help me.

This is my as2 code:

Code: Select all

function walk(horizontal,vertical){
   avatarMC._x += horizontal;
   avatarMC._y += vertical;
   if (inited)
   {
      if (!_global.isBusy)
      {
         var px:Number = int(avatarMC._x)
         var py:Number = int(avatarMC._y)
         
         
         
         if ((px > avatarW/2) && (px < areaW - avatarW/2) && (py > avatarH/2) && (py < areaH - avatarH/2))
         {
            // save new variables
            // Please note that init is set to false:
            // this means that we're only moving somewhere and we don't need to init tha avatar
            smartfox.setUserVariables({px:px, py:py, init:false})
             
            // method derived from the [flashAPI].as
            // moves the mc using the "Quint" equation, with "InOut" easying
            // to the new px,py position in 100 milliseconds.
         }
      }       
   }
}

if(Key.isDown(Key.RIGHT)){
   _root.walk(5,0);
}

if(Key.isDown(Key.LEFT)){
   _root.walk(-5,0);
}
myMouse.onMouseDown = function()
{
   _root.walk(0,-5);
}
if(Key.isDown(Key.DOWN)){
   _root.walk(0,5);

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 46 guests