Implementing Shooting Through Operators and Observables

Learn to implement shoot functionality using the merge Observable and controlling it through the timestamp operator.

It’s a bit scary seeing the hordes of enemies coming at us, but all we can do is move out of the way and hope they don’t see us.

How about we give our hero the ability to shoot at the evil alien spaceships?

We want our spaceship to shoot whenever we click the mouse or press the spacebar, so we’ll create an Observable for each event and merge them into a single Observable called playerShots. Notice that we filter the keydown Observable by the key code of the spacebar, 32:

Get hands-on with 1400+ tech skills courses.