Skip to main content

Truetype fonts, sprite rotation, and in the future more extensions for Pyxel.

Project description

PyxelXL

I am using this for my own game dev purposes, and this is beta-quality software.

"Bloat"-ish extensions for Pyxel, that might not fit the retro game-dev aesthetic, but fits more for the "let's throw up some constraints for our game jam so we can focus" aesthetic.

Fast TTF drawing for Pyxel, including support for layout (align, wrapping) and experimental support for anti-aliasing. This library is in the works to become a general purpose "bloated" set of extensions for Pyxel, but for now it only includes a font rendering extension and a center-rotation extension.

alt screenshot

Installation

You can install PyxelXL using pip:

pip install pyxelxl

Usage

To use a TTF font in your Pyxel application:

import pyxel
from pyxelxl.font import Font
from pyxelxl import LayoutOpts

roboto = Font("/path/to/Roboto-Regular.ttf")
zh_font = Font("/path/to/zpix.ttf")

class App:
    def __init__(self):
        pyxel.init(160, 120, title="PyxelXL Example")
        pyxel.run(self.update, self.draw)

    def update(self):
        pass

    def draw(self):
        pyxel.cls(1)
        roboto.text(
            0,
            0,
            "Hello, World! Antialiased",
            7,
            font_size=16,
            layout=LayoutOpts(max_width=160, horizontal_align="center"),
        )
        zh_font.text(
            0,
            40,
            "我能吞下玻璃而不伤身体" * 5,
            7,
            font_size=12,
            layout=LayoutOpts(max_width=160),
        )
        roboto.text(
            0, 80, "Hello, World! Not antialiased", 15, font_size=16, threshold=128
        ) # layout is optional. Thresholding makes the text look pixelated.

App()

LayoutOpts, Text Wrapping, and Alignment

LayoutOpts is a class used to define layout options for text rendering in pyxelxl.

Attributes

  • max_width: Optional[int]

    • The maximum width of the text layout in pixels. If None, the width is not constrained. Wrapping will occur if the text exceeds this width.
  • max_height: Optional[int]

    • The maximum height of the text layout in pixels. If None, the height is not constrained.
  • horizontal_align: str

    • The horizontal alignment of the text. It can be one of the following values:
      • "left"
      • "center"
      • "right"
    • Default is "left".
  • vertical_align: str

    • The vertical alignment of the text. It can be one of the following values:
      • "top"
      • "center"
      • "bottom"
    • Default is "top".
  • line_height_mult: Optional[float]

    • The multiplier for line height. If None, the line height is determined by the font size.

Center Rotation

from pyxelxl.rotate import blt
blt(80 - 32, 60 - 32, self.square, 0, 0, 64, 64, colkey=0, rot=self.angle)
# The rotation center is at (80, 60) in the global coordinate system.

Advantages

  • Fast for font rendering
  • Easy multi-font size support
  • Anti-aliasing algorithm for non-pixel fonts

Acknowledgements

Heavy-lifting done by fontdue, and obviously this library will not be here if not for Pyxel.

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

pyxelxl-0.0.17.tar.gz (165.2 kB view hashes)

Uploaded Source

Built Distributions

pyxelxl-0.0.17-cp37-abi3-win_amd64.whl (319.5 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

pyxelxl-0.0.17-cp37-abi3-win32.whl (310.6 kB view hashes)

Uploaded CPython 3.7+ Windows x86

pyxelxl-0.0.17-cp37-abi3-musllinux_1_2_x86_64.whl (664.0 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ x86-64

pyxelxl-0.0.17-cp37-abi3-musllinux_1_2_i686.whl (686.0 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ i686

pyxelxl-0.0.17-cp37-abi3-musllinux_1_2_armv7l.whl (759.8 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARMv7l

pyxelxl-0.0.17-cp37-abi3-musllinux_1_2_aarch64.whl (670.5 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARM64

pyxelxl-0.0.17-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (493.0 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

pyxelxl-0.0.17-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (497.4 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

pyxelxl-0.0.17-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (494.9 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

pyxelxl-0.0.17-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (514.0 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.5+ i686

pyxelxl-0.0.17-cp37-abi3-macosx_11_0_arm64.whl (430.2 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

pyxelxl-0.0.17-cp37-abi3-macosx_10_12_x86_64.whl (435.5 kB view hashes)

Uploaded CPython 3.7+ macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page