Skip to content

Commit

Permalink
docs: Update docs, SpriteFont (#2979)
Browse files Browse the repository at this point in the history
Remove duplicate example of SpriteFont
  • Loading branch information
sellmark authored Mar 23, 2024
1 parent 7210182 commit d7c97c2
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions site/docs/04-graphics/04.1-text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -149,41 +149,15 @@ await game.start();

## SpriteFont

Sometimes you want to use a custom font based on a sprite sheet of character glyphs
Sometimes you want to use a custom font based on your [spritesheet](#spritesheet) of character glyphs

Example `sprite-font.png` file:

![Custom pixel art glyphs](debug-font.png)

```typescript
const image = new ex.ImageSource('./path/to/sprite-font.png')

const spriteSheet = SpriteSheet.fromImageSource({
image: image,
grid: {
rows: 3,
columns: 16,
spriteWidth: 16,
spriteHeight: 16,
},
})

const spriteFont = new SpriteFont({
alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,!\'&."?-()+ ',
caseInsensitive: true,
spriteSheet: this._spriteSheet,
spacing: -6,
})
const spriteFontImage = new ex.ImageSource('./path/to/sprite-font.png')

const text = new ex.Text({
text: 'some text with a sprite font!',
font: spriteFont,
})
```

#### SpriteFont

Sometimes you want to use text of your own creation from a [spritesheet](#spritesheet),

```typescript
const spriteFontSheet = ex.SpriteSheet.fromImageSource({
image: spriteFontImage,
grid: {
Expand All @@ -193,14 +167,12 @@ const spriteFontSheet = ex.SpriteSheet.fromImageSource({
spriteHeight: 16
}
});

const spriteFont = new ex.SpriteFont({
alphabet: '0123456789abcdefghijklmnopqrstuvwxyz,!\'&."?- ',
caseInsensitive: true,
spriteSheet: spriteFontSheet
});
});

const text = new ex.Text({
text: 'This is sprite font text!!',
font: spriteFont
Expand Down

0 comments on commit d7c97c2

Please sign in to comment.