[COLOR=#333233]Hi guys. I’m working on a game in AS 2, but have encountered a problem - the game gets steadily more laggy as you progress through the levels, but the lag only occurs when a key is pressed (usually frequent presses or keys being held down - in particular, the arrow keys to move the player).[/COLOR]
[COLOR=#333233]
[/COLOR]
[COLOR=#333233]To move the player:
[/COLOR]
[COLOR=#333233]if(keyup == true && keyleft == false && keyright == false && keydown == false) {[/COLOR]
[COLOR=#333233] _root.hero._y -= moveup;[/COLOR]
[COLOR=#333233]
And I’m using a function to determine key down:[/COLOR]
[COLOR=#333233]
[/COLOR]
[COLOR=#333233]keyListener.onKeyDown = function() {[/COLOR]
[COLOR=#333233]if (keyisdownvar(keyupdown) && !keyisdownvar(keyleftdown) && !keyisdownvar(keyrightdown) && !keyisdownvar(keydowndown)) {[/COLOR]
[COLOR=#333233] keyup = true;[/COLOR]
[COLOR=#333233] keyleft = false;[/COLOR]
[COLOR=#333233] keydown = false;[/COLOR]
[COLOR=#333233] keyright = false;[/COLOR]
}
[COLOR=#333233] }[/COLOR]
[COLOR=#333233]
There’s nothing wrong with the code per se - I was just wondering if there is a more efficient way of doing this that will work better towards reducing lag?
Thanks guys.[/COLOR]