kaplayjs / kaplay

🦖 A JavaScript/TypeScript Game Library that feels like a game, fun
https://kaplayjs.com
MIT License
525 stars 35 forks source link

docs: extent of setCursor #386

Closed dragoncoder047 closed 1 month ago

dragoncoder047 commented 2 months ago

Now that we have custom fake mouse objects (#372) it's a bit counterintuitive and maybe a bit wasteful of yet another onUpdate hook to have to write onUpdate(() => setCursor("none")) to hide the system cursor.

So I was thinking that the global setCursor function could have a second parameter sticky, default false, when it is true, it sets the "default" cursor that the canvas cursor gets reset to every frame, instead of the current frame's cursor. Then you could just do setCursor("none", true) and let the browser handle constantly hiding the cursor.

I'd open a PR, but I can't find the spot in the code where the cursor gets reset at the end of the frame.

amyspark-ng commented 2 months ago

you don't have to do setCursor("none") on update!! that could lag the game i think, you could probably set it at the start and that'd work well

dragoncoder047 commented 2 months ago

you could probably set it at the start and that'd work well

Never mind actually, that seems to work. I guess this is a docs issue because the docs for setCursor say:

setCursor(style: Cursor): void Set cursor style (check Cursor type for possible values). Cursor will be reset to "default" every frame so use this in a per-frame action.

(emphasis mine)

amyspark-ng commented 2 months ago

you could probably set it at the start and that'd work well

Never mind actually, that seems to work. I guess this is a docs issue because the docs for setCursor say:

setCursor(style: Cursor): void Set cursor style (check Cursor type for possible values). Cursor will be reset to "default" every frame so use this in a per-frame action.

(emphasis mine)

oh that's pretty weird, i set it once at the start of my game and it worked, so not sure what could be it

lajbel commented 2 months ago

Maybe also an option in fakeCursor component?