-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Closes #3060 ## Changes: - Adds sandbox test with repro - Updates spritefont to include scale
- Loading branch information
Showing
10 changed files
with
176 additions
and
6 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Sprite Font Rendering</title> | ||
</head> | ||
<body> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
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,46 @@ | ||
class TestFontMeasuringScene extends ex.Scene { | ||
font1: ex.SpriteFont; | ||
font2: ex.SpriteFont; | ||
async onInitialize(game: ex.Engine) { | ||
super.onInitialize(game); | ||
let loader = new ex.DefaultLoader(); | ||
let fontImage = new ex.ImageSource('font.png'); | ||
loader.addResource(fontImage); | ||
await game.start(loader); | ||
|
||
let fontSpriteSheet = ex.SpriteSheet.fromImageSource({ | ||
image: fontImage, | ||
grid: { columns: 1, rows: 45, spriteWidth: 10, spriteHeight: 10 } | ||
}); | ||
|
||
this.font1 = this.createFont(fontSpriteSheet); | ||
this.font2 = this.createFont(fontSpriteSheet); | ||
this.font2.scale = ex.vec(2, 2); | ||
} | ||
|
||
createFont(spriteSheet: ex.SpriteSheet) { | ||
return new ex.SpriteFont({ | ||
alphabet: '01234567890.- ©][ABCDEFGHIJKLMNOPQRSTUVWXYZ|/', | ||
caseInsensitive: true, | ||
spriteSheet | ||
}); | ||
} | ||
onActivate(ctx: ex.SceneActivationContext) { | ||
const text = 'brown fox jumps over the lazy dog'; | ||
let m1 = this.font1.measureText(text); | ||
console.log('font 1', m1.dimensions); //330,10, OK | ||
let m2 = this.font2.measureText(text); | ||
console.log('font 2', m2.dimensions); //330,10, should be 660,20 | ||
} | ||
} | ||
|
||
var engineSpriteFont = new ex.Engine({ | ||
width: 600, | ||
height: 600, | ||
pixelArt: true, | ||
scenes: { | ||
start: TestFontMeasuringScene | ||
} | ||
}); | ||
|
||
engineSpriteFont.start('start'); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Sprite Font Rendering</title> | ||
</head> | ||
<body> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
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,37 @@ | ||
class TestFontScene extends ex.Scene { | ||
async onInitialize(game: ex.Engine) { | ||
super.onInitialize(game); | ||
let loader = new ex.DefaultLoader(); | ||
let fontImage = new ex.ImageSource('./font.png'); | ||
loader.addResource(fontImage); | ||
await game.start(loader); | ||
let fontSpriteSheet = ex.SpriteSheet.fromImageSource({ | ||
image: fontImage, | ||
grid: { columns: 1, rows: 45, spriteWidth: 10, spriteHeight: 10 } | ||
}); | ||
let font = new ex.SpriteFont({ | ||
alphabet: '01234567890.- ©][ABCDEFGHIJKLMNOPQRSTUVWXYZ|/', | ||
caseInsensitive: true, | ||
spriteSheet: fontSpriteSheet, | ||
scale: ex.vec(4, 4) | ||
}); | ||
let lbl = new ex.Label({ | ||
pos: ex.vec(10, 10), | ||
anchor: ex.vec(0, 0), | ||
text: '-brown fox jumps \nover the lazy dog', | ||
spriteFont: font | ||
}); | ||
this.add(lbl); | ||
} | ||
} | ||
|
||
var engineSpriteFont = new ex.Engine({ | ||
width: 600, | ||
height: 600, | ||
pixelArt: true, | ||
scenes: { | ||
start: TestFontScene | ||
} | ||
}); | ||
|
||
engineSpriteFont.start('start'); |
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.