Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Added many examples for on events #477

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tristanperrow
Copy link
Contributor

Added examples for the following events:

  • onAdd()
  • onDestroy()
  • onLoading()
  • onError()
  • onResize()
  • onCleanup()
  • onGamepadConnect()
  • onGamepadDisconnect()
  • onKeyRelease()
  • onMouseDown()
  • onMousePress()
  • onMouseRelease()
  • onMouseMove()
  • onHide()
  • onShow()
  • onGamepadButtonDown()
  • onGamepadButtonPress()
  • onGamepadButtonRelease()
  • onGamepadStick()

Copy link

pkg-pr-new bot commented Oct 23, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/kaplayjs/kaplay@477

commit: 28e15d8

Copy link
Collaborator

@lajbel lajbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many are fine, let some comments

* @example
* ```js
* // This will run when the object is added.
* onAdd("addTag", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addTag looks as bad example, maybe bomb, enemy or any real world name

* @example
* ```js
* // This will run when the object is destroyed.
* onDestroy("destroyTag", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as onAdd

* debug.log("ohbye")
* })
*
* let objectToDestroy = add([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as onAdd, should be generic names like enemy or bullet

Comment on lines +1806 to +1807
* if (m == `left`)
* cookies++
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use our format with brackets or change to inline if(m == "left") cookies++;

Comment on lines +2190 to +2196
* let player = add([
* pos(center()),
* anchor(`center`),
* sprite(`bean`),
* area(),
* body(),
* {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example doesn't need all this components, with pos and sprite is already understable

@@ -1717,6 +2140,40 @@ export interface KAPLAYCtx<
): KEventController;
/**
* Register an event that runs when user releases any gamepad button.
*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complicated, but looks good

* // gamepad player controls
* setGravity(200)
*
* let player = add([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same, not that much comps needed

* // gamepad player jump
* setGravity(200)
*
* let player = add([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about many comps

* @example
* ```js
* // basic car with brakes
* let car = add([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about comps, I think we should mantain simple the ones in controller, I like these examples but can be real examples, not the example of the function, should be simpler

*
* @since v3001.0
* @group Events
*/
onShow(action: () => void): KEventController;
/**
* Register an event that runs every frame when certain gamepad buttons are held down.
*
* @example
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same about complexity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants