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

Emit "actionstart" and "actioncomplete" events #2856

Closed
mattjennings opened this issue Dec 28, 2023 · 1 comment · Fixed by #2857
Closed

Emit "actionstart" and "actioncomplete" events #2856

mattjennings opened this issue Dec 28, 2023 · 1 comment · Fixed by #2857

Comments

@mattjennings
Copy link
Contributor

It would be useful the ActionsComponent emitted events when starting/completing actions

Context

I have a moving platform that has its path defined by actions

    const platform = new MovingPlatform(
      {
        x: 300,
        y: 50,
        width: 100,
        height: 16,
      },
      (actions) =>
        actions.repeatForever((builder) =>
          builder.moveBy(0, -50, 40).moveBy(0, 50, 40)
        )
    )

I have some particular logic that I need to run whenever the platform changes direction that should happen immediately after the velocity is changed. Hooking into an event would be a very nice way to solve this.

Proposal

Action component the following events containing the relevant action:

  • actionstart
  • actioncomplete

These can be either on the actor or the actions component, or both? This would also fire for each action in repeatForever etc.

type ActionStartEvent {
    action: ex.Action
}

type ActionCompleteEvent {
   action: ex.Action
}

this.on('actioncomplete', (ev) => {
   
})
@eonarheim
Copy link
Member

100% down for this!

eonarheim pushed a commit that referenced this issue Dec 29, 2023
…2857)


Closes #2856

## Changes:

- Added `actionstart` and `actioncomplete` events to the Actor that are fired when an action starts and completes
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 a pull request may close this issue.

2 participants