© Engin Arslan 2018
Engin ArslanLearn JavaScript with p5.jshttps://doi.org/10.1007/978-1-4842-3426-6_11

11. Events

Engin Arslan1 
(1)
Toronto, Ontario, Canada
 

In Chapter 6, we learned about a p5.js variable called mouseIsPressed, which assumes the value to be true while the mouse is being pressed and false for all other instances.

We also learned that this is not a great way of capturing user input as the execution speed of the draw function can make it hard to get this variable updated in a reliable way. In this chapter we’ll review other ways of handling user input inside p5.js, namely, the events, which solve this problem. Using events, we can capture the user input outside the draw function loop.

There are numerous event functions in p5.js that ...

Get Learn JavaScript with p5.js: Coding for Visual Learners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.