Tuesday, June 26, 2012

[Action Script] How to give function to multiple keys sequentially pressed? June,2012

I'm designing a platform game with standard left, right, jump mechanics.

However, I want to get this movement mechanic where if the user holds left or right key followed by the opposite direction key, the movement will continue in that direction but decrease in speed. Here's what I have:
Code: function onEnterFrame(event:Event):void
                {
                        if (leftKey == true)
                        {
                                if ( rightKey == true)
                                {
                                        playerJeebz1_mc.x -= mainSpeed/2;
                                }
                                else
                                {
                                        playerJeebz1_mc.x -= mainSpeed;
                                }
                        }
                       
                        else if (rightKey == true)
                        {
                                if (leftKey == true)
                                {
                                        playerJeebz1_mc.x += mainSpeed/2;
                                }
                                else
                                {
                                        playerJeebz1_mc.x += mainSpeed;
                                }
                        }
                }If I hold left then right, I move twice as slow.
But if I hold right then left, I end up moving left still.
Any ideas how I could fix this?
How to give function to multiple keys sequentially pressed?

Related Post



0 comments: