Skip to content

New main loop structure to better allow running PyGame in browser #3187

@davidfstr

Description

@davidfstr

Currently it is possible to run PyGame applications in a web browser using projects like Pyodide and pygbag (see these demos), however both projects require restructuring the PyGame event loop in a non-standard way:

Regular PyGame event loop:

clock = pygame.time.Clock()
fps = 60
def run_game():
    while True:
        do_something()
        draw_canvas()
        clock.tick(fps)

Asyncified PyGame event loop:

import asyncio

async def run_game():
    while True:
        do_something()
        draw_canvas()
        await asyncio.sleep(1 / fps)

This is a problem because PyGame applications cannot be run as-is in the web browser. They must be first edited to use a non-standard structure that only works in the browser.

Imagine if PyGame provided a new event loop API that worked both inside AND outside the web browser. SDL 3 has a new main callbacks API which allows an SDL-based program using it to run normally both instead and outside a browser. Perhaps PyGame could provide a new event loop API that could target this new main callbacks API.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions