forked from spritejs/spritejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
22 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
const {createCanvas} = require('canvas') | ||
const fs = require('fs') | ||
|
||
const Label = require('../../lib/label').default | ||
const {BaseSprite} = require('sprite-core') | ||
|
||
async function drawSprites(canvas, sprites) { | ||
function drawSprites(canvas, sprites) { | ||
const {width, height} = canvas, | ||
context = canvas.getContext('2d') | ||
|
||
context.clearRect(0, 0, width, height) | ||
for(let i = 0; i < sprites.length; i++) { | ||
/* eslint-disable no-await-in-loop */ | ||
await sprites[i].draw(context, true) | ||
/* eslint-enabel no-await-in-loop */ | ||
sprites[i].connect(context).draw() | ||
} | ||
return canvas.toBuffer() | ||
} | ||
|
||
const text1 = new Label('SpriteJS.org 中国') | ||
|
||
text1.attr({ | ||
anchor: 0.5, | ||
pos: [400, 300], | ||
font: '48px Arial', | ||
color: '#fff', | ||
bgcolor: 'blue', | ||
renderMode: 'stroke', | ||
lineHeight: 75, | ||
padding: [0, 50, 0, 50], | ||
const s = new BaseSprite() | ||
|
||
s.attr({ | ||
bgcolor: 'red', | ||
anchor: [0.5, 0.5], | ||
pos: [100, 100], | ||
size: [50, 50], | ||
}) | ||
|
||
const canvas = createCanvas(800, 600) | ||
const canvas = createCanvas(200, 200) | ||
|
||
;(async function () { | ||
const buffer = await drawSprites(canvas, [text1]) | ||
fs.writeFileSync('../../test/img/label-48px-Arial.png', buffer) | ||
const buffer = await drawSprites(canvas, [s]) | ||
fs.writeFileSync('../../test/img/basesprite-bgcolor-red.png', buffer) | ||
}()) | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.