CreateJS / EaselJS

The Easel Javascript library provides a full, hierarchical display list, a core interaction model, and helper classes to make working with the HTML5 Canvas element much easier.
http://createjs.com/
MIT License
8.11k stars 1.97k forks source link

Mousemovement Performance improvement #1072

Open Matt-Maerz opened 2 years ago

Matt-Maerz commented 2 years ago

Hello everyone, I am looking for an alternative/better performing MouseMovement method. I read the following in another entry:

https://github.com/CreateJS/EaselJS/issues/977 I do recommend writing your own hit testing if you don't need pixel perfect hit interactions though!

So I assume the problem is in the hitTest method, which analyzes pixel perfect everything. I still dared to modify the CreateJS lib. Does anyone here have experience and can help me how to adjust which method? Thank you!

danzen commented 1 year ago

Hi @Matt-Maerz - you may want to check out the various hitTests in ZIM, a framework built on CreateJS. We do several types of hitTests that are not pixel based and even the pixel based ones we do a calculated bounds check first. May as well see if the bounds are hitting with an equation before testing pixels. This dramatically increases the efficiency of hitTests. ZIM is at https://zimjs.com and the tips page https://zimjs.com/tips.html#HITTEST. You can see the types of hitTests in the docs https://zimjs.com/docs.html under the methods section. image

hitTestPoint() is the same as the CreateJS hitTest. hitTestReg() same as above but tests against the registration point hitTestBounds() is a fast calculation between bounds of objects hitTestCircleRect() is a fast calculation between a circle and a rectangle hitTestGrid() is a fast calculation for grid sections hitTestRect() and hitTestCircle() test any shape against points around a rectangle or circle (slower as shape based) etc.

danzen commented 1 year ago

Oh!!! Sorry, @Matt-Maerz - I just re-read the issue and it seems like you may have been talking about just rollovers in CreateJS using pixel based detection. Okay. I will leave the last response there in case you are wanting to do your own hitTests. We have been fine with mouseover speed in general and keep it turned on by default in ZIM. We then use mouseChildren and mouseEnabled false when objects do not need to be interacted with. We have simplified this with a mouse() and noMouse() methods available on all our DisplayObjects.