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

fix: [#1431] Dispatch the hidePlayButton on the Button Event to prevent that keep on the screen on some situations [#1431] #2066

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
-
### Added

- `withEngine` utils support an aditional options parameter to override the Engine default options.
- Story to show a play / pause implementation.
- `ex.Animation` now support `totalDuration` that will calculate automatically each frame duration based on how many frames have.
-
### Changed

- Internal Actions implementation converted to ECS system and component, this is a backwards compatible change with v0.25.0
- `ex.ActionsSystem` and `ex.ActionsComponent` now wrap the existing `ex.ActionContext`
- Actions can be shared with all entities now!
- Revert VSCode Workbench Colors
- Dispatch the `hidePlayButton` on the Button Event to prevent that keep on the screen on some situations [#1431].
- Revert VSCode Workbench Colors
-
### Deprecated

- Actions `asPromise()` renamed to `toPromise()`
Expand Down
4 changes: 3 additions & 1 deletion src/engine/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export class Loader extends Class implements Loadable<Loadable<any>[]> {
*/
public showPlayButton(): Promise<void> {
if (this.suppressPlayButton) {
this.hidePlayButton();
return Promise.resolve();
} else {
this._playButtonShown = true;
Expand All @@ -255,6 +256,8 @@ export class Loader extends Class implements Loadable<Loadable<any>[]> {
const startButtonHandler = (e: Event) => {
// We want to stop propogation to keep bubbling to the engine pointer handlers
e.stopPropagation();
// Hide Button after click
this.hidePlayButton();
Copy link
Member

Choose a reason for hiding this comment

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

👍

resolve();
};
this._playButton.addEventListener('click', startButtonHandler);
Expand Down Expand Up @@ -312,7 +315,6 @@ export class Loader extends Class implements Loadable<Loadable<any>[]> {
// See: https://github.com/excaliburjs/Excalibur/issues/262
// See: https://github.com/excaliburjs/Excalibur/issues/1031
await WebAudio.unlock();
this.hidePlayButton();

return (this.data = this._resourceList);
}
Expand Down
47 changes: 47 additions & 0 deletions src/stories/Engine.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Actor, Color, Loader } from '../engine';
import { Font, ImageSource, Text } from '../engine/Graphics';
import { withEngine } from './utils';

import heartTexture from './assets/heart.png';

export default {
title: 'Engine'
};

export const playButton: Story = withEngine(
async (game) => {
const heartTx = new ImageSource(heartTexture);
const loader = new Loader([heartTx]);
await game.start(loader);
game.setAntialiasing(false);
game.currentScene.camera.pos.setTo(game.halfDrawWidth, game.halfDrawHeight);
game.currentScene.camera.zoom = 4;
const heart = new Actor({
x: game.currentScene.camera.x,
y: game.currentScene.camera.y,
width: 50,
height: 50
});
heart.on('pointerdown', async (_evnt: ex.Input.PointerEvent) => {
if (!game.isPaused()) {
game.stop();
await loader.showPlayButton();
game.start();
}
});
heart.actions.repeatForever((actions) => {
actions.scaleBy(2, 2, 2).scaleBy(-2, -2, 2);
});
const text = new Text({
text: 'Pause',
color: Color.White,
font: new Font({ size: 4 })
});
heart.graphics.add(heartTx.toSprite());
heart.graphics.add(text);
game.add(heart);
},
{
suppressPlayButton: false
}
);
8 changes: 5 additions & 3 deletions src/stories/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DisplayMode, Engine, Input, Logger } from '../engine';
import { DisplayMode, Engine, EngineOptions, Input, Logger } from '../engine';

interface HTMLCanvasElement {
gameRef?: Engine;
Expand Down Expand Up @@ -34,8 +34,9 @@ const onDomMutated: MutationCallback = (records) => {
/**
* Helper to generate Storybook game engine instance
* @param storyFn The storybook fn to pass the engine to
* @param options Engine options to override the default behavior of the engine on storybook (see EngineOptions)
*/
export const withEngine = (storyFn: (game: Engine, args?: Record<string, any>) => void) => {
export const withEngine = (storyFn: (game: Engine, args?: Record<string, any>) => void, options?: EngineOptions) => {
if (!observer) {
observer = new MutationObserver(onDomMutated);
observer.observe(document.getElementById('root'), { childList: true, subtree: true });
Expand All @@ -47,7 +48,8 @@ export const withEngine = (storyFn: (game: Engine, args?: Record<string, any>) =
canvasElement: canvas,
displayMode: DisplayMode.FitScreen,
suppressPlayButton: true,
pointerScope: Input.PointerScope.Canvas
pointerScope: Input.PointerScope.Canvas,
...options
Copy link
Member

Choose a reason for hiding this comment

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

👍

});

Logger.getInstance().info('Press \'d\' for debug mode');
Expand Down