-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from galacean/feat/addPixi
Add sprte and text benchmark for pixi.js
- Loading branch information
Showing
10 changed files
with
141 additions
and
289 deletions.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
/** | ||
* @title Sprite | ||
* @category Benchmark | ||
*/ | ||
|
||
import * as PIXI from "pixi.js"; | ||
|
||
const canvas = document.getElementById("canvas") as HTMLCanvasElement; | ||
const app = new PIXI.Application(); | ||
app | ||
.init({ | ||
canvas: canvas, | ||
resizeTo: window, | ||
width: canvas.width, | ||
height: canvas.height, | ||
}) | ||
.then(() => { | ||
PIXI.Assets.load([ | ||
{ | ||
src: "https://mdn.alipayobjects.com/huamei_w6ifet/afts/img/A*YwyMRq8_O-4AAAAAAAAAAAAADjCHAQ/original", | ||
loadParser: "loadTextures", | ||
}, | ||
{ | ||
src: "https://mdn.alipayobjects.com/huamei_w6ifet/afts/img/A*ClJLS6U4HtsAAAAAAAAAAAAADjCHAQ/original", | ||
loadParser: "loadTextures", | ||
}, | ||
]).then((textureRecord) => { | ||
const col = 88; | ||
const row = 90; | ||
const offsetX = 5; | ||
const offsetY = 10; | ||
// 中心点所在行列 | ||
const centerX = col * 0.5; | ||
const centerY = row * 0.5; | ||
// 屏幕宽高 | ||
const screen = app.screen; | ||
const halfWidth = screen.width * 0.5; | ||
const halfHeight = screen.height * 0.5; | ||
const sprites = []; | ||
const texture1 = | ||
textureRecord[ | ||
"https://mdn.alipayobjects.com/huamei_w6ifet/afts/img/A*YwyMRq8_O-4AAAAAAAAAAAAADjCHAQ/original" | ||
]; | ||
const texture2 = textureRecord['https://mdn.alipayobjects.com/huamei_w6ifet/afts/img/A*ClJLS6U4HtsAAAAAAAAAAAAADjCHAQ/original']; | ||
for (let i = 0; i < row; ++i) { | ||
for (let j = 0; j < col; ++j) { | ||
const sprite = new PIXI.Sprite(i % 2 === 0 ? texture1 : texture2); | ||
app.stage.addChild(sprite); | ||
sprite.scale = 0.045; | ||
sprite.anchor.set(0.5, 0.5); | ||
sprite.x = halfWidth + (j - centerX) * offsetX + 5; | ||
sprite.y = halfHeight + (i - centerY) * offsetY + 10; | ||
sprites.push(sprite); | ||
} | ||
} | ||
|
||
app.ticker.add((time) => { | ||
for (let i = 0, n = sprites.length; i < n; ++i) { | ||
sprites[i].rotation += 0.01 * time.deltaTime; | ||
} | ||
}); | ||
}); | ||
}); |
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,55 @@ | ||
/** | ||
* @title Text | ||
* @category Benchmark | ||
*/ | ||
|
||
import * as PIXI from "pixi.js"; | ||
|
||
const canvas = document.getElementById("canvas") as HTMLCanvasElement; | ||
const app = new PIXI.Application(); | ||
app | ||
.init({ | ||
canvas: canvas, | ||
resizeTo: window, | ||
width: canvas.width, | ||
height: canvas.height, | ||
}) | ||
.then(() => { | ||
const col = 22; | ||
const row = 90; | ||
const offsetX = 20; | ||
const offsetY = 10; | ||
// 中心点所在行列 | ||
const centerX = col * 0.5; | ||
const centerY = row * 0.5; | ||
// 屏幕宽高 | ||
const screen = app.screen; | ||
const halfWidth = screen.width * 0.5; | ||
const halfHeight = screen.height * 0.5; | ||
const texts = []; | ||
const style = new PIXI.TextStyle({ | ||
fontFamily: "Arial", | ||
fontSize: 20, | ||
fill: 0xffffff, | ||
}); | ||
for (let i = 0; i < row; ++i) { | ||
for (let j = 0; j < col; ++j) { | ||
const text = new PIXI.Text({ | ||
text: "hello", | ||
style, | ||
}); | ||
app.stage.addChild(text); | ||
text.anchor.set(0.5, 0.5); | ||
text.scale = 0.8; | ||
text.x = halfWidth + (j - centerX) * offsetX + 10; | ||
text.y = halfHeight + (i - centerY) * offsetY + 10; | ||
texts.push(text); | ||
} | ||
} | ||
|
||
app.ticker.add((time) => { | ||
for (let i = 0, n = texts.length; i < n; ++i) { | ||
texts[i].rotation += 0.01 * time.deltaTime; | ||
} | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.