Flash Action Script Key Press Restrictions


hello, making pacman game , using following script movement of character.

 

onclipevent (enterframe) {

          speed = 10;

          if (key.isdown(key.left))

          {

                    this._x -= speed;

                    _root.char.gotoandstop(2);

          }

          if (key.isdown(key.right))

          {

                    this._x += speed;

                    _root.char.gotoandstop(1);

          }

          if (key.isdown(key.up))

          {

                    this._y -= speed;

                    _root.char.gotoandstop(3);

          }

          if (key.isdown(key.down))

          {

                    this._y += speed;

                    _root.char.gotoandstop(4);

          }

}

 

the problem i'm having when press right , down keys, or other 2 keys result in diagonal movement, character moves in direction.  want character able move right, left, , down.  the   _root.char.gotoandstop(3); part of script character faces in direction.  there way restrict number of keys can pressed @ once one? or make first of 2 keys or second of 2 keys pressed used? if not, there way make right , down key press result in diagonal movement faces character way? or stops character entirely? throuroughly appreciate on matter! in advance!

 

walt

one way incorpate "else" 's last 3 conditionals.  make first key determined down key determines movement.

 

onclipevent (enterframe) {

          speed = 10;

          if (key.isdown(key.left))

          {

                    this._x -= speed;

                    _root.char.gotoandstop(2);

          } else  if (key.isdown(key.right))          {

                   this._x += speed;

                    _root.char.gotoandstop(1);

          } else if (key.isdown(key.up))          {

                    this._y -= speed;

                    _root.char.gotoandstop(3);

          } else if (key.isdown(key.down))           {

                    this._y += speed;

                    _root.char.gotoandstop(4);

          }

}



More discussions in Adobe Animate CC - General


adobe

Comments

Popular posts from this blog

Falang and too many redirects - Joomla! Forum - community, help and support

Infinite loop detected in JErrorInfinite loop detected in JError - Joomla! Forum - community, help and support

logged out from joomla! - Joomla! Forum - community, help and support