Care to move to a newer SDL with your Pygame knowledge? Then you should know one thing or two about PySDL2 before hacking code, since it is completely different from Pygame. Do not let that fact scare you away, the basics with graphics and sound are still the same (as they are fundamental), but you will not find many similarities to the Pygame API within PySDL2.
Todo
More details, examples, etc.
TODO
Pygame is implemented as a mixture of Python, C and Assembler code, wrapping 3rd party libraries with CPython API interfaces. PySDL2 in contrast is written in pure Python, using ctypes to interface with the C interfaces of 3rd party libraries.
pygame | sdl2 |
---|---|
init() | sdl2.init() where appropriate |
quit() | sdl2.quit() where appropriate |
error | No equivalent |
get_error() | sdl2.get_error() |
set_error() | sdl2.set_error() |
get_sdl_version() | sdl2.version.get_version() |
get_sdl_byteorder() | sdl2.endian.SDL_BYTEORDER |
register_quit() | No equivalent planned |
encode_string() | Encoding and decoding strings is done implicitly, where necessary |
encode_file_path() | Encoding and decoding strings is done implicitly, where necessary |
PySDL2 does not feature any CD-ROM related interfaces. They were removed in SDL2 and mule does not provide its own facilities.
You can find a similar class in sdl2.ext.color.Color. It does not feature a set_length() or correct_gamma() method, though.
PySDL2 does not feature any pre-defined cursor settings at the moment.
pygame.display | sdl2 |
---|---|
init() | sdl2.ext.init() |
quit() | sdl2.ext.quit() |
get_init() | sdl2.SDL_WasInit() |
set_mode() | mule.video.window.Window |
get_surface() | mule.video.window.Window.get_surface() |
flip() | mule.video.window.Window.refresh() |
update() | mule.sdl2.video.update_window_surface_rects() |
get_driver() | mule.sdl2.video.get_current_video_driver() |
Info | No equivalent yet |
get_wm_info() | mule.sdl2.syswm.get_window_wm_info() |
list_modes() | mule.sdl2.video.get_num_display_modes() |
mode_ok() | mule.sdl2.video.get_closest_display_mode() |
gl_get_attribute() | mule.sdl2.video.gl_get_attribute() |
gl_set_attribute() | mule.sdl2.video.gl_set_attribute() |
get_active() | No equivalent yet |
iconify() | mule.video.window.Window.minimize() |
toggle_fullscreen() | mule.sdl2.video.set_window_fullscreen() |
set_gamma() | mule.sdl2.video.set_window_brightness() |
set_gamma_ramp() | mule.sdl2.video.set_window_gamma_ramp() |
set_icon() | mule.sdl2.video.set_window_icon() |
set_caption() | mule.video.window.Window.title |
get_caption() | mule.video.window.Window.title |
set_palette() | mule.sdl2.surface.set_surface_palette() |
pygame.draw | mule |
---|---|
rect() | mule.sdl2.render.render_draw_rect(), mule.video.draw.fill() |
polygon() | No equivalent yet |
circle() | No equivalent yet |
ellipse() | No equivalent yet |
arc() | No equivalent yet |
lines() | mule.sdl2.render.render_draw_lines(), mule.video.draw.line() |
aaline() | No equivalent yet |
aalines() | No equivalent yet |
pygame.event | mule |
---|---|
pump() | mule.sdl2.events.pump_events() |
get() | mule.sdl2.events.poll_event() |
poll() | mule.sdl2.events.poll_event() |
wait() | mule.sdl2.events.wait_event() |
peek() | mule.sdl2.events.peep_events() |
clear() | mule.sdl2.events.flush_events() |
event_name() | No equivalent planned |
set_blocked() | mule.sdl2.events.event_state() |
get_blocked() | mule.sdl2.events.event_state() |
set_allowed() | mule.sdl2.events.event_state() |
set_grab() | mule.sdl2.video.set_window_grab() |
get_grab() | mule.sdl2.video.get_window_grab() |
post() | mule.sdl2.events.peep_events() |
Event | mule.sdl2.events.SDL_Event |
pygame.font | mule |
---|---|
init() | mule.sdlttf.init() |
quit() | mule.sdlttf.quit() |
get_init() | No equivalent planned |
get_default_font() | No equivalent planned |
get_fonts() | mule.font.get_fonts() |
match_font() | mule.font.get_font() |
SysFont | No equivalent planned |
Font | No equivalent yet |
mule does not feature direct FreeType support at the moment.
mule does not feature SDL_gfx support at the moment.
pygame.image | mule |
---|---|
load() | mule.sdlimage.load(), mule.video.image.load_image() |
save() | mule.sdl2.surface.save_bmp() |
get_extended() | mule.sdlimage.is_bmp() et al. |
tostring() | No equivalent yet |
fromstring() | No equivalent yet |
frombuffer() | No equivalent yet |
pygame.joystick | mule |
---|---|
init() | mule.sdl2.init() |
quit() | mule.sdl2.quit() |
get_init() | mule.sdl2.was_init() |
get_count() | mule.sdl2.joystick.joystick_num_joysticks() |
Joystick() | mule.sdl2.joystick.SDL_Joystick and related functions |
pygame.key | mule |
---|---|
get_focused() | mule.sdl2.keyboard.get_keyboard_focus() |
get_pressed() | mule.sdl2.keyboard.get_keyboard_state() |
get_mods() | mule.sdl2.keyboard.get_mod_state() |
set_mods() | mule.sdl2.keyboard.set_mod_state() |
set_repeat() | Based on the OS/WM settings, no equivalent |
get_repeat() | Based on the OS/WM settings, no equivalent |
name() | mule.sdl2.keyboard.get_key_name() |
Constants in mule are spread across the different packages and modules, depending on where they originate from.
SDL_mixer is currently not supported by mule. The focus is set on OpenAL usage through mule.openal and mule.audio.
pygame.mixer | mule |
---|---|
init() | No necessity to explicitly initialize |
quit() | No necessity to explicitly quit |
get_init() | No necessity to explicitly initialize |
stop() | mule.audio.SoundSource.request = SOURCE_STOP |
pause() | mule.audio.SoundSource.request = SOURCE_PAUSE |
unpause() | mule.audio.SoundSource.request = SOURCE_PLAY |
fadeout() | No equivalent yet |
set_num_channels() | Depends on the mule.audio.SoundSink device and bound mule.audio.SoundSource instances. |
get_num_channels() | Depends on the mule.audio.SoundSink device and bound mule.audio.SoundSource instances. |
set_reserved() | Depends on the mule.audio.SoundSink device and bound mule.audio.SoundSource instances. |
find_channel() | No equivalent planned |
get_busy() | No equivalent yet |
Sound | mule.audio.SoundData for the buffer, mule.audio.SoundSource for the volume settings and playback |
Channel | mule.audio.SoundSource |
See pygame.mixer.
pygame.mouse | mule |
---|---|
get_pressed() | mule.sdl2.mouse.get_mouse_state() |
get_pos() | mule.sdl2.mouse.get_mouse_state() |
get_rel() | mule.sdl2.mouse.get_relative_mouse_state() |
set_pos() | mule.sdl2.mouse.warp_mouse_in_window() |
set_visible() | mule.sdl2.mouse.show_cursor() |
get_focused() | mule.sdl2.mouse.get_mouse_focus() |
set_cursor() | mule.sdl2.mouse.set_cursor() |
get_cursor() | mule.sdl2.mouse.get_cursor() |
No such module is planned for mule.
You can work with YUV overlays by using the mule.sdl2.render with mule.sdl2.render.SDL_Texture objects.
You can access pixel data of sprites and surfaces directly via the mule.video.pixelaccess.PixelView class. It does not feature comparision or extractions methods.
No such functionality is available for mule. Rectangles are represented via mule.sdl2.rect.SDL_Rect for low-level SDL2 wrappers or 4-value tuples.
mule offers basic text-based clipboard access via the mule.sdl2.clipboard module. A feature-rich clipboard API as for Pygame does not exist yet.
No such module is available for mule yet.
mule uses a different approach of rendering and managing sprite objects via a component-based system and the mule.video.sprite.Sprite class. A sprite module as for Pygame is not planned.
pygame.Surface | mule |
---|---|
blit() | mule.video.sprite.SpriteRenderer.render(), mule.sdl2.surface.blit_surface() |
convert() | mule.sdl2.surface.convert_surface() |
convert_alpha() | mule.sdl2.surface.convert_surface() |
copy() | mule.sdl2.surface.convert_surface() |
fill() | mule.video.draw.fill(), mule.sdl2.surface.fill_rect(), mule.sdl2.surface.fill_rects() |
scroll() | No equivalent yet |
set_colorkey() | mule.sdl2.surface.set_color_key() |
get_colorkey() | mule.sdl2.surface.get_color_key() |
set_alpha() | mule.sdl2.surface.set_surface_alpha_mod() |
get_alpha() | mule.sdl2.surface.get_surface_alpha_mod() |
lock() | mule.sdl2.surface.lock_surface() |
unlock() | mule.sdl2.surface.unlock_surface() |
mustlock() | mule.sdl2.surface.SDL_MUSTLOCK() |
get_locked() | mule.sdl2.surface.SDL_Surface.locked |
get_locks() | No equivalent planned |
get_at() | Direct access to the pixels for surfaces can be achieved via the mule.video.pixelaccess.PixelView class |
set_at() | Direct access to the pixels for surfaces can be achieved via the mule.video.pixelaccess.PixelView class |
get_at_mapped() | No equivalent planned |
get_palette() | via mule.sdl2.surface.SDL_Surface.format and the mule.sdl2.pixels.SDL_PixelFormat.palette attribute. |
get_palette_at() | mule.sdl2.pixels.SDL_Palette.colors[offset] |
set_palette() | mule.sdl2.surface.set_surface_palette() |
set_palette_at() | mule.sdl2.pixels.SDL_Palette.colors[offset] |
map_rgb() | mule.sdl2.pixels.map_rgb() |
unmap_rgb() | mule.sdl2.pixels.get_rgb() |
set_clip() | mule.sdl2.surface.set_clip_rect() |
get_clip() | mule.sdl2.surface.get_clip_rect() |
subsurface | No equivalent yet |
get_parent() | As for subsurface |
get_abs_parent() | As for subsurface |
get_offset() | As for subsurface |
get_abs_offset() | As for subsurface |
get_size() | mule.video.sprite.Sprite.size, mule.sdl2.surface.SDL_Surface.size |
get_width() | mule.video.sprite.Sprite.size[0], mule.sdl2.surface.SDL_Surface.size[0] |
get_height() | mule.video.sprite.Sprite.size[1], mule.sdl2.surface.SDL_Surface.size[1] |
get_rect() | mule.video.sprite.Sprite.area |
get_bitsize() | mule.sdl2.pixels.SDL_PixelFormat.BitsPerPixel |
get_bytesize() | mule.sdl2.pixels.SDL_PixelFormat.BytesPerPixel |
get_flags() | mule.sdl2.surface.SDL_Surface.flags |
get_pitch() | mule.sdl2.surface.SDL_Surface.pitch |
get_masks() | mule.sdl2.pixels.SDL_PixelFormat.Rmask, ... |
get_shifts() | mule.sdl2.pixels.SDL_PixelFormat.Rshift, ... |
get_losses() | mule.sdl2.pixels.SDL_PixelFormat.Rloss, ... |
get_bounding_rect() | No equivalent yet |
get_view() | mule.video.pixelaccess.PixelView |
get_buffer() | mule.video.pixelaccess.PixelView or mule.sdl2.surface.SDL_Surface.pixels |
2D and 3D pixel access can be achieved via the mule.video.pixelaccess.PixelView class in environments without numpy. Simplified numpy-array creation with direct pixel access (similar to pygame.surfarray.pixels2d() and pygame.surfarray.pixels3d()) is available via mule.video.pixelaccess.pixels2d() and mule.video.pixelaccess.pixels3d().
pygame.time | mule |
---|---|
get_ticks() | mule.sdl2.timer.get_ticks() |
wait() | mule.sdl2.timer.delay() |
delay() | mule.sdl2.timer.delay() |
Clock | No equivalent yet |
The are no transformation helpers in mule at moment. Those might be implemented later on via numpy helpers, the Python Imaging Library or other 3rd party packages.
pygame.version | mule |
---|---|
ver | mule.__version__ |
vernum | mule.version_info |