Adding the Player’s Spaceship in the Game Using Observables

Learn to use Observables to add a player to the spaceship video game.

Now that we have our beautiful starry background, we’re ready to program the hero’s spaceship. Even though it’s the most important object in the game, our spaceship is deceptively simple. It’s an Observer of mouse moves that emits the current mouse x-coordinate and a constant y-coordinate. The player only moves horizontally, so we never need to change the y-coordinate:

Get hands-on with 1200+ tech skills courses.