Okay, fellas, I am pasting what could be relevant code. Of course, if this does not help, I will provide the source to try out.
So, here is the Draw event of the player, which handles his collisions. I am using CollisionFree method here.
- Code: Select all
//gravity
yvelocity++;view.yvelocity++;if (yvelocity>7){yvelocity=6;view.yvelocity=6;}
//slowing down before landing on something
if(CollisionFree("Event Actor",x,y+yvelocity)==false){
yvelocity=1;view.yvelocity=1;
}
//to make sure we can jump only after we landed on the platform
if(CollisionFree("Event Actor",x,y+1)==false){ yvelocity=0;view.yvelocity=0; jump=1;}
//bumping into obstacles on left and right
if(CollisionFree("Event Actor",x-2,y)==false) {wleft=0;} else {wleft=1;}
if(CollisionFree("Event Actor",x+2,y)==false) {wright=0;} else {wright=1;}
Here is what happens on keydown (this is for LEFT arrow)
- Code: Select all
if(wleft==1) {xvelocity=-2;}
else {xvelocity=0;}
And here is what happens on keyup (this is for LEFT arrow)
- Code: Select all
xvelocity=0;
So the idea here is that the Draw Actor event checks whether an actor can move, say, left. If he can, then the flag wleft is set to 1. Whereas the keydown event will set xvelocity only if this flag allows it. Then keyup event will set xvelocity back to 0.
What seems to happenAt some point in time one of the keyup events fails to register - or at least so it seems. I even added to the screen pictures of keys, which would change color when I press them and go back to normal on keyup. On occasions of the bug I would see that the picture of the relevant key is in state "pressed".
The biggest problem is that it is not easy to reproduce. When I try to press three keys at the same time, this does not occur. But it does happen during normal gameplay and happens very often, say, every 15-20 seconds. This makes it very frustrating to play. But also extremely difficult to debug.
I also made a screen video of myself playing, to track the situations with the kys when that occurs and was able to catch that several times, but pressing seemingly same combination does not reproduce the error. In fact, I haven't been able to reproduce it even once by pressing the keys on purpose to get the bug. But as soon as i start playing the game, jumping down from platforms and collecting items - that's when this might randomly happen. As if my behavior during the game is slightly different that how I press buttons when trying to reproduce.