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: [#2421] Match Screenshot AA with Screen #2428

Merged
merged 5 commits into from
Jul 23, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed issue where screenshots from `ex.Engine.screenshot()` did not match the smoothing set on the engine.
- Fixed incorrect event type returned when `ex.Actor.on('postupdate', (event) => {...})`.
- Fixed issue where using numerous `ex.Text` instances would cause Excalibur to crash webgl by implementing a global font cache.
- Fixed issue where child entities did not inherit the scene from their parent
Expand Down
1 change: 1 addition & 0 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,7 @@ O|===|* >________________>\n\
screenshot.width = finalWidth;
screenshot.height = finalHeight;
const ctx = screenshot.getContext('2d');
ctx.imageSmoothingEnabled = this.screen.antialiasing;
ctx.drawImage(this.canvas, 0, 0, finalWidth, finalHeight);

const result = new Image();
Expand Down
31 changes: 30 additions & 1 deletion src/spec/EngineSpec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as ex from '@excalibur';
import { TestUtils } from './util/TestUtils';
import { ExcaliburAsyncMatchers, ExcaliburMatchers } from 'excalibur-jasmine';
import { Engine } from '@excalibur';

/**
*
Expand Down Expand Up @@ -722,6 +721,36 @@ describe('The engine', () => {
await expectAsync(hidpiImage).toEqualImage(flushWebGLCanvasTo2D(engine.canvas));
});

it('can screen shot and match the anti-aliasing with a half pixel when pixelRatio != 1.0', async () => {
const engine = TestUtils.engine({
width: 200,
height: 200,
pixelRatio: 1.2,
suppressHiDPIScaling: false,
antialiasing: false,
snapToPixel: false
}, []);
const clock = engine.clock as ex.TestClock;
const img = new ex.ImageSource('src/spec/images/EngineSpec/sprite.png');
await img.load();
const actor = new ex.Actor({
x: 40.5,
y: 40.0,
scale: ex.vec(2, 2)
});
actor.graphics.use(img.toSprite());
engine.add(actor);
TestUtils.runToReady(engine);

clock.step(1);
const screenShotPromise = engine.screenshot();
clock.step(1);

const image = await screenShotPromise;

await expectAsync(image).toEqualImage('src/spec/images/EngineSpec/screenshot.png', 1.0);
});

describe('lifecycle overrides', () => {
let engine: ex.Engine;
beforeEach(() => {
Expand Down
Binary file added src/spec/images/EngineSpec/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/spec/images/EngineSpec/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/spec/images/EngineSpec/sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.