-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
eonarheim
merged 2 commits into
excaliburjs:main
from
catrielmuller:catriel/play-button-cleaned-up-on-stop
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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 }); | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}); | ||
|
||
Logger.getInstance().info('Press \'d\' for debug mode'); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍