0

I am developing a flash games in which a letter symbol flies from right side of the screen and ends at left i need to process some keyboard events i.e when a letter is on the vertical bar the letter should stop there. Can any one guide me how can i achieve this enter image description here

Abdul Khaliq

1 Answer 1

1

An easy approach is to put the created "letters" in an Array and call an update function (TimerEvent.TIMER or Event.ENTER_FRAME) wich moves/animates the letters. If the letter is inside the vertical bar (in range of x) and the correct key is pressed then you just lock it there.

stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUpHandler);
private function onKeyUpHandler(event : KeyboardEvent) : void
{
    for(var i : int = 0 ; i < _letterList.length ; i++)
    {
        if(isInRange(_letterList[i]))
        {
            if(_letterList[i].validateKey(event.keyCode))
            {
                // lock on position and skip further updates
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.