Skip to content

Commit

Permalink
feat: Actor.actions.flash(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Nov 3, 2024
1 parent e14f866 commit 4a35f74
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Added new `actor.actions.flash(...)` `Action` to flash a color for a period of time
- Added a new `ex.NineSlice` `Graphic` for creating arbitrarily resizable rectangular regions, useful for creating UI, backgrounds, and other resizable elements.
```typescript
var nineSlice = new ex.NineSlice({
Expand Down
24 changes: 18 additions & 6 deletions src/engine/Actions/ActionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { Meet } from './Action/Meet';
import { Vector } from '../Math/vector';
import { Entity } from '../EntityComponentSystem/Entity';
import { Action } from './Action';
import { Color } from '../Color';
import { Flash } from './Action/Flash';

/**
* The fluent Action API allows you to perform "actions" on
Expand Down Expand Up @@ -327,21 +329,31 @@ export class ActionContext {
* to the provided value by a specified time (in milliseconds). This method is
* part of the actor 'Action' fluent API allowing action chaining.
* @param opacity The ending opacity
* @param time The time it should take to fade the actor (in milliseconds)
* @param duration The time it should take to fade the actor (in milliseconds)
*/
public fade(opacity: number, time: number): ActionContext {
this._queue.add(new Fade(this._entity, opacity, time));
public fade(opacity: number, duration: number): ActionContext {
this._queue.add(new Fade(this._entity, opacity, duration));
return this;
}

/**
* This will cause an actor to flash a specific color for a period of time
* @param color
* @param duration The duration in milliseconds
*/
public flash(color: Color, duration: number = 1000) {
this._queue.add(new Flash(this._entity, color, duration));
return this;
}

/**
* This method will delay the next action from executing for a certain
* amount of time (in milliseconds). This method is part of the actor
* 'Action' fluent API allowing action chaining.
* @param time The amount of time to delay the next action in the queue from executing in milliseconds
* @param duration The amount of time to delay the next action in the queue from executing in milliseconds
*/
public delay(time: number): ActionContext {
this._queue.add(new Delay(time));
public delay(duration: number): ActionContext {
this._queue.add(new Delay(duration));
return this;
}

Expand Down
22 changes: 16 additions & 6 deletions src/engine/Actions/ActionsComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EasingFunction } from '../Util/EasingFunctions';
import { ActionQueue } from './ActionQueue';
import { RotationType } from './RotationType';
import { Action } from './Action';
import { Color } from '../Color';

export interface ActionContextMethods extends Pick<ActionContext, keyof ActionContext> {}

Expand Down Expand Up @@ -225,20 +226,29 @@ export class ActionsComponent extends Component implements ActionContextMethods
* to the provided value by a specified time (in milliseconds). This method is
* part of the actor 'Action' fluent API allowing action chaining.
* @param opacity The ending opacity
* @param time The time it should take to fade the actor (in milliseconds)
* @param duration The time it should take to fade the actor (in milliseconds)
*/
public fade(opacity: number, time: number): ActionContext {
return this._getCtx().fade(opacity, time);
public fade(opacity: number, duration: number): ActionContext {
return this._getCtx().fade(opacity, duration);
}

/**
* This will cause an actor to flash a specific color for a period of time
* @param color
* @param duration The duration in milliseconds
*/
public flash(color: Color, duration: number = 1000) {
return this._getCtx().flash(color, duration);
}

/**
* This method will delay the next action from executing for a certain
* amount of time (in milliseconds). This method is part of the actor
* 'Action' fluent API allowing action chaining.
* @param time The amount of time to delay the next action in the queue from executing in milliseconds
* @param duration The amount of time to delay the next action in the queue from executing in milliseconds
*/
public delay(time: number): ActionContext {
return this._getCtx().delay(time);
public delay(duration: number): ActionContext {
return this._getCtx().delay(duration);
}

/**
Expand Down

0 comments on commit 4a35f74

Please sign in to comment.