A Python library to render text from bitmap font images
Project description
Pygame-BitmapFont
A lightweight and easy-to-use library for rendering bitmap fonts in Pygame.
Overview
Pygame-BitmapFont provides a simple way to load and render text using pre-rendered bitmap font images and associated font data files. This approach is often preferred in game development for its performance and consistent look across different platforms.
Key Features:
- Easy Integration: Designed specifically for Pygame, ensuring smooth integration into your game projects.
- Multiple Font Formats: Supports custom
.jsonhuman-readable and editable font formats. - Efficient Rendering: Leverages Pygame's
Surfaceand drawing capabilities for fast text rendering. - Customizable: Offers options for color, scaling and text alignment.
- Clear Examples: Comes with illustrative examples to get you started quickly.
- Tools Included: Comes with CLI
bitmapfont-extracttool for easy preparation of.jsonfonts from bitmap images. - Installable via pip: Easily install the library using the Python package installer.
Installation
- Prerequisites: Make sure you have Pygame installed in your Python environment. If not, you can install it using pip:
pip install pygame
- Install via pip (Recommended): Once the package is available on PyPI, you can install BitmapFont using:
pip install git+https://github.com/xdoko01/Pygame-BitmapFont.git
orpip install pgbitmapfont
- Alternatively (for development or if not on PyPI):
- Download or Clone: Clone the entire repository:
git clone [https://github.com/xdoko01/Pygame-BitmapFont.git](https://github.com/xdoko01/Pygame-BitmapFont.git) cd Pygame-BitmapFont
- Place the
pgbitmapfontpackage: Ensure thepgbitmapfontdirectory (containing the library's__init__.pyand other modules) is in your Python project's site-packages directory or within your project structure where Python can import it.
- Download or Clone: Clone the entire repository:
Usage
Here's a basic example of how to use the Pygame-BitmapFont library in your Pygame project after installing it (either via pip or by placing the package):
import pygame
from pgbitmapfont import BitmapFont
# Initialize Pygame
pygame.init()
# Set up display
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Pygame-BitmapFont Example")
# Load the font
font = BitmapFont("path/to/your/font.json")
# Text to render
text = "Hello, Pygame!"
text_position = (100, 100)
# Game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Clear the screen
screen.fill((0, 0, 0)) # Black
# Render and blit the text
screen.blit(font.render(text)[0], text_position)
# Update the display
pygame.display.flip()
# Quit Pygame
pygame.quit()
Usage of bitmapfont-extract tool
Once the Pygame-BitmapFont (pgbitmapfont) package is installed via pip, you can use the following command to run the bitmapfont-extract tool:
bitmapfont-extract --img font_image.png --out font.json
Controls
- Select the suitable grid resolution by 'PgUp', 'PgDown'
- Select the cell with texture by mouse and/or cursor keys
- Press INSERT and enter the character under which it will be stored.
- Once done, press RETURN to save and continue.
Tips
- once saved, the cell is grey
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pgbitmapfont-0.1.4.tar.gz.
File metadata
- Download URL: pgbitmapfont-0.1.4.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
358bbd858f37d3dc723edaba6d2e06b20ace9c7a1b908b25365ba34024c52669
|
|
| MD5 |
f0b71c2aab276d77b3217e974a5a7e3d
|
|
| BLAKE2b-256 |
0f1991f0d38890b4019b34819a438e06a8b3837058d48cfba057c9b5d649f08d
|
File details
Details for the file pgbitmapfont-0.1.4-py3-none-any.whl.
File metadata
- Download URL: pgbitmapfont-0.1.4-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa3c90b58ef06792a20346bf18b716e88bfaf6ebd3b867c4fd3814bfae1d24bc
|
|
| MD5 |
247fa6f4aecb52b0c307f87c5db686c9
|
|
| BLAKE2b-256 |
14446c2b4d2834f5f1a759367b9584c73b8b02ce1b58968da1adf5c98836bfad
|