@toasty-engine/loader
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@toasty-engine/loader

A utility package for loading assets in game development. This package provides simple tools for loading textures and fonts for use in games.

Features

  • 🖼️ Load textures from URLs or ImageBitmapSource
  • 🔤 Load and register custom fonts
  • ⚡ Asynchronous loading with Promise-based API
  • 🎮 WebGPU-ready ImageBitmap output
  • 🛠️ Simple and intuitive API

Why should I use this?

When developing games, proper asset loading is crucial for:

  • Loading textures for sprites and backgrounds
  • Adding custom fonts for UI and text elements
  • Handling asynchronous asset loading efficiently
  • Preparing assets in WebGPU-compatible formats

This package provides a streamlined solution for asset loading in games, handling the complexities of loading and preparing assets for use in WebGPU applications.

Installation

bun add @toasty-engine/loader

Usage

Loading Textures

import { loadTexture } from '@toasty-engine/loader';

// Load a texture from a URL
const texture = await loadTexture('path/to/texture.png');

// Or load from an existing ImageBitmapSource
const customTexture = await loadTexture(existingImageSource);

// The returned ImageBitmap can be used to create a WebGPU texture
// Use the texture in your WebGPU rendering code

Loading Custom Fonts

import { loadFont } from '@toasty-engine/loader';

// Load and register a custom font
const font = await loadFont('MyGameFont', 'path/to/font.ttf');

// The font is now available in your CSS and Canvas operations
// Use it in your styles
element.style.fontFamily = 'MyGameFont';

// Or in Canvas context
context.font = '16px MyGameFont';

License

This package is part of the Toasty Engine project and is licensed under the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i @toasty-engine/loader

Weekly Downloads

3

Version

0.0.1

License

MIT

Unpacked Size

51.6 kB

Total Files

20

Last publish

Collaborators

  • hello-story75