soulwire/sketch.js

Autostart: false not working

Opened this issue · 1 comments

When set to false the canvas will start to draw with the mouse anyway. I have tried mousemove and touchmove events. Same behaviour across browsers. Any idea? Thanks!

Here's the jsFiddle:

http://jsfiddle.net/bitflower/ss3dkhnz/3/

Hi! Thanks for trying sketch and for finding creating this issue. The problem is that mouse events are bound and triggered even if the sketch isn't running (i.e the update/draw loop is stopped) which is the state it's in when you tell sketch not to autostart.

On the one hand, it would make sense to prevent these events from firing if the sketch isn't running. However, you may still want to receive things like resize events even if it isn't and in some cases even mouse events (perhaps you're tracking the mouse but not drawing.) Regardless, the current architecture means that all events are handled in the same way and so I'd need to add special cases for this.

The intended meaning for the running flag (which is what's toggled when you start or stop a sketch) was to reflect state of the update/draw loop which happens each frame. I think this is an interesting case though and worth thinking about.

In the meantime and as a quick fix you can just check the running flag in your mouse handlers (example) or for your specific use case, use the dragging flag (example).

I hope that solves your problem for now and if you and others think that stopping (or not starting) the sketch should mean that all events are disabled then I can make this change to the library.