Lesson 2 · Creative Coding
Moving with key presses.
Up to now your sprites have done the same thing every run. A game needs the player to change what happens.
The simplest way is the keyboard: when [space] key pressed starts a script the moment that key goes down.
One script per key. Four arrow keys means four small scripts — and each one can live on the sprite it controls, which keeps everything tidy.
This distinction is the difference between a game that feels good and one that feels broken:
when [right arrow] key pressed is an event. It fires once per press. Hold the key and movement is jerky, with a pause before it repeats — the same delay you see when holding a key in a text box.if <key [right arrow] pressed?> then inside a forever loop checks constantly. Hold the key and the sprite glides smoothly.For menus and one-off actions, use the event. For movement in a game, use the forever-loop version. Nearly every beginner uses the first, wonders why their game feels clunky, and never finds out why.
5 more parts in this lesson
Walkthroughs, code labs, mini-games and the checkpoint quiz unlock when you buy the course.