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

Actions repeat forever if not cleared #1891

Closed
herobank110 opened this issue May 8, 2021 · 4 comments · Fixed by #1896
Closed

Actions repeat forever if not cleared #1891

herobank110 opened this issue May 8, 2021 · 4 comments · Fixed by #1896
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior

Comments

@herobank110
Copy link

Steps to Reproduce

  import { Actor, Color, EasingFunctions, Engine } from 'excalibur';

  const a = new Actor({ x: 10, y: 10, width: 10, height: 10, color: Color.White });
  a.actions
    .easeTo(10, 100, 1000, EasingFunctions.EaseInCubic)
    .delay(250)
    .callMethod(() => {
      // clear to do 2 repeats, but resets position at first delay
      // a.actions.clearActions();
      a.actions
        .easeTo(100, 100, 1000, EasingFunctions.EaseInCubic)
        .delay(250)
        .easeTo(10, 100, 1000, EasingFunctions.EaseInCubic)
        .delay(250)
        .repeat(2);  // this 2nd round of actions loops forever!
    });

  (e => e.add(a) || e.start())(new Engine());

Expected Result

Expected down movement followed by movement right and left twice before stopping.

Actual Result

Down movement, then right and left movement forever.

Environment

  • browsers and versions: Safari (14.0.3)
  • operating system: MacOS
  • Excalibur versions: 0.24.5

Current Workaround

Schedule function calls with setTimeout using pre set delays instead of repeating actions.

@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label May 15, 2021
@eonarheim
Copy link
Member

@herobank110 Thanks for the issue, I have a theory where the bug is coming from in excalibur.

My guess based on your workaround, is that repeat inside the callAction() does indeed do accumulate N+1 actions as you mentioned in the discussion post. The way repeat is implemented is it copies the current actions in the context and re-adds them https://github.com/excaliburjs/Excalibur/blob/main/src/engine/Actions/ActionContext.ts#L257

CallMethod is technically not yet done, so it get's re-added as part of the repeat, which repeats again and again 😢 possibly a fix is to change how these are dequeued in the context? Or change how repeat selects things for repeating?

@eonarheim
Copy link
Member

One thought I had was to change up the repeat api to make it clear what is repeating, instead of trying to guess based on the current queue.

What do you think of something like?

 a.actions
    .easeTo(10, 100, 1000, EasingFunctions.EaseInCubic)
    .delay(250)
    .repeat(reContext => {
      // Specific actions to repeat
       reContext
        .easeTo(100, 100, 1000, EasingFunctions.EaseInCubic)
        .delay(250)
        .easeTo(10, 100, 1000, EasingFunctions.EaseInCubic)
        .delay(250)
     }, 2);

@herobank110
Copy link
Author

I think it's better like that, it looks more like a loop from most programming languages.

@herobank110
Copy link
Author

Also that way you can define all the actions in one go

eonarheim added a commit that referenced this issue May 19, 2021
Closes #1891
Bonus Closes #635 

## Changes:

- Changes the repeat/repeatForever api to be more clear (breaking change, no longer introspects the current action queue)

```typescript
 a.actions
    .easeTo(10, 100, 1000, EasingFunctions.EaseInCubic)
    .delay(250)
    .repeat(repeatBuilder => {
      // Specific actions to repeat
       repeatBuilder
        .easeTo(100, 100, 1000, EasingFunctions.EaseInCubic)
        .delay(250)
        .easeTo(10, 100, 1000, EasingFunctions.EaseInCubic)
        .delay(250)
     }, 2); // Repeats twice
   ```
- Light refactoring to actions
   - Separate action types into separate files
   - Change ActionContext to only support 1 actor at a time (multi actor unused after groups was deprecated long ago)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants