A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: how do i make a character move when a key is pressed but not holding the key?

  1. #1
    Junior Member
    Join Date
    Aug 2023
    Posts
    1

    how do i make a character move when a key is pressed but not holding the key?

    i am making a pac man recreation in flash, and i need to make the controls for pac-man, i want him to move forever when i press a key, but not holding it, so, can anyone give me the script for that? im using macromedia flash 8, and the actionscript version must be actionscript 2.0

  2. #2
    Junior Member
    Join Date
    Aug 2024
    Posts
    1
    I'm currently working on my own Pac-Man game. My problem at the moment is whenever my character hits an item, it lags LOL!

    var PC01_ACCELX = 0;
    var PC01_ACCELY = 0;

    function onEnterFrame()
    {

    _root.PC01._y += _root.PC01_ACCELY;
    _root.PC01._x += _root.PC01_ACCELX;

    if( Key.isDown( Key.UP ))
    {
    _root.PC01_ACCELY = -1;
    _root.PC01_ACCELX = 0;
    }

    else if( Key.isDown( Key.DOWN ))
    {
    _root.PC01_ACCELY = 1;
    _root.PC01_ACCELX = 0;
    }

    else if( Key.isDown( Key.LEFT ))
    {

    _root.PC01_ACCELY = 0;
    _root.PC01_ACCELX = -1;
    }

    else if( Key.isDown( Key.RIGHT ))
    {
    _root.PC01_ACCELY = 0;
    _root.PC01_ACCELX = 1;
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center