does anyone here know why most of the time getkey is put inside it's own loop on the turorials, etc. on this site? it seems completely useless to me to do that, a waste of a few bytes.
it's so that the whole lot of code doesn't have to loop through, doing calculations it really doesn't have to do if Getkey=0. Instead, we just cycle through 3 lines of code. That way, when someone hits a key, it is registered immediately.
Often, it will also reduce flicker. If you just had a loop in which a sprite was constantly erased, possibly moved by the arrow keys, and then redrawn, it would keep flickering when no key is pressed. Put getKey in its own loop and you make sure that the sprite is only erased when a key is pressed (which usually means it's going to be moved).
It really wouldn't save space if you took out the getKey loop, because a lot of the time, you'd end up making the getKey=0 case a special case anyway and those few bytes you didn't "waste" will be back five times over.
true, but I do something a little different when I want a moving object, I only use line commands, like this.
and so on. It's much easier, because it erases and draws lines within the same loop.
here is what I use for the arrow.
It works great.
if you were programing a game where you were the only thing active on the screen, you would use the
Method, but this would not allow you to have another thing active while you were not moving. So then you would have to use the
It all depends on the circumstance.