Skip to main content

A Pythonic API wrapper for SDL2.

Project description

sdl2hl is a Python package providing a friendly, Pythonic wrapper around the SDL2 library. sdl2hl calls SDL2 using Kevin Howell’s sdl2-cffi package (which can be found here: https://github.com/kahowell/sdl2-cffi). sdl2hl maintains sdl2-cffi’s advantages of using cffi and being zlib licensed, while providing an API that hides the gruesome details of the FFI layer from the user.

Goals

The goals of sdl2hl are:

  • Provide a straightforward, Pythonic API on top of the functionality provided by SDL2.

  • Provide good documentation, independent of the SDL2 documentation.

  • Cover as much of the SDL2 API as possible, excluding elements of the API that do not provide value to a program written in Python (e.g. thread management and shared object loading).

An explicit anti-goal of sdl2hl is providing any significant functionality beyond that which is provided by SDL2. sdl2hl may be a reasonable foundation of a larger game library, but it will not become one itself.

Versioning

sdl2hl versioning follows the semver 2.0 standard. Once sdl2hl hits 1.0, every effort will be made to prevent backwards incompatible changes. If a backwards incompatible change absolutely cannot be avoided, sdl2hl’s major version will be incremented. However, since sdl2hl has not hit 1.0, for now there may be breaking changes at any time. Sorry.

License

sdl2hl is licensed under the same zlib license as SDL2 and sdl2-cffi. More details can be found in the LICENSE.txt file that (should) be found in this distribution.

Contributions

Contributions are welcome! If you encounter a bug or have a request or suggestion please open an issue on github at https://github.com/jdoda/sdl2hl/issues . If you want to submit a patch, please open a github pull request at https://github.com/jdoda/sdl2hl/pulls .

Example

import sys

import sdl2hl


BACKGROUND_COLOR = (0,0,0,255)
AVATAR_COLOR = (255,0,0,255)


sdl2hl.init()
window = sdl2hl.Window()
renderer = sdl2hl.Renderer(window)
avatar = sdl2hl.Rect(w=64, h=64)

while True:
    for event in sdl2hl.events.poll():
        if event.type == sdl2hl.QUIT:
            sdl2hl.quit()
            sys.exit()
        elif event.type == sdl2hl.KEYDOWN and event.keysym.sym == sdl2hl.K_LEFT:
            avatar.x -= 1
        elif event.type == sdl2hl.KEYDOWN and event.keysym.sym == sdl2hl.K_RIGHT:
            avatar.x += 1
        elif event.type == sdl2hl.KEYDOWN and event.keysym.sym == sdl2hl.K_UP:
            avatar.y -= 1
        elif event.type == sdl2hl.KEYDOWN and event.keysym.sym == sdl2hl.K_DOWN:
            avatar.y += 1

    renderer.draw_color = BACKGROUND_COLOR
    renderer.clear()
    renderer.draw_color = AVATAR_COLOR
    renderer.fill_rect(avatar)

    renderer.present()

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

sdl2hl-0.2.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

sdl2hl-0.2.0-py2.py3-none-any.whl (21.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sdl2hl-0.2.0.tar.gz.

File metadata

  • Download URL: sdl2hl-0.2.0.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sdl2hl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c384d45134981d26f971e9b0c707d1ab27fb6b038ec5d540aea1830be23dafc0
MD5 35ef6d731dfbd4929f7e09b2f9a37c84
BLAKE2b-256 d0bfb941425fd2ce948f6a2829c505745d7cc9180a09852b7c3e526f6ba3beae

See more details on using hashes here.

File details

Details for the file sdl2hl-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sdl2hl-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3e216942e5f094d6193fab5635062825687e789b7a020c1680f98b2b982360f5
MD5 029dde1e15fb202409728980fd4b0441
BLAKE2b-256 001880b05049e96e45825324c5653e14e802038e8378d7b44196f9585e624c1c

See more details on using hashes here.

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