Skip to content

Commit 1906c2a

Browse files
authored
Add render to texture spritemap visual test (#485)
2 parents d914169 + fab564f commit 1906c2a

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

examples/tests/rtt-spritemap.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* If not stated otherwise in this file or this component's LICENSE file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2023 Comcast Cable Communications Management, LLC.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the License);
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import type { ExampleSettings } from '../common/ExampleSettings.js';
21+
import spritemap from '../assets/spritemap.png';
22+
23+
export async function automation(settings: ExampleSettings) {
24+
// Snapshot single page
25+
await test(settings);
26+
await settings.snapshot();
27+
}
28+
29+
export default async function test({ renderer, testRoot }: ExampleSettings) {
30+
const FONT_SIZE = 45;
31+
32+
renderer.createTextNode({
33+
text: `Render to Texture Spritemap Test`,
34+
fontSize: FONT_SIZE,
35+
offsetY: -5,
36+
parent: testRoot,
37+
});
38+
39+
const spriteMapTexture = renderer.createTexture('ImageTexture', {
40+
src: spritemap,
41+
});
42+
43+
spriteMapTexture.on('load', (dimensions) => {
44+
console.log('Spritemap Texture loaded', dimensions);
45+
});
46+
47+
const rttNode = renderer.createNode({
48+
x: 200,
49+
y: 200,
50+
width: 300,
51+
height: 300,
52+
parent: testRoot,
53+
rtt: true,
54+
clipping: true,
55+
zIndex: 5,
56+
colorTop: 0xfff00fff,
57+
colorBottom: 0x00ffffff,
58+
});
59+
60+
renderer.createNode({
61+
x: 0,
62+
y: 0,
63+
width: 300,
64+
height: 300,
65+
parent: rttNode,
66+
color: 0xff0000ff,
67+
});
68+
69+
renderer.createTextNode({
70+
x: 0,
71+
y: 0,
72+
text: 'Render to texture',
73+
parent: rttNode,
74+
fontSize: 48,
75+
color: 0xffffffff,
76+
fontFamily: 'Ubuntu',
77+
});
78+
79+
function execTest(
80+
positionX: number,
81+
sourceX: number,
82+
title: string,
83+
): Promise<boolean> {
84+
const character = renderer.createTexture('SubTexture', {
85+
texture: spriteMapTexture,
86+
x: sourceX,
87+
y: 0,
88+
width: 100,
89+
height: 150,
90+
});
91+
92+
renderer.createNode({
93+
x: positionX,
94+
y: 80,
95+
width: 100,
96+
height: 150,
97+
texture: character,
98+
parent: rttNode,
99+
});
100+
101+
return new Promise((resolve, reject) => {
102+
renderer.once('idle', () => {
103+
resolve(true);
104+
});
105+
});
106+
}
107+
108+
await execTest(0, 0, 'Character 1');
109+
await execTest(60, 100, 'Character 2');
110+
await execTest(120, 200, 'Character 3');
111+
await execTest(180, 300, 'Character 4');
112+
await execTest(240, 400, 'Character 5');
113+
}
32.8 KB
Loading

0 commit comments

Comments
 (0)