Created
January 14, 2024 23:00
-
-
Save gabrieldp/920951232e78266c644e357fd2afbaf3 to your computer and use it in GitHub Desktop.
raylib - pyray multiple rendering windows example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyray | |
from raylib.colors import ( | |
RAYWHITE, | |
DARKGRAY, | |
MAROON, | |
) | |
from multiprocessing import Process | |
def launch_window(title): | |
# Initialization | |
SCREEN_WIDTH = 800 | |
SCREEN_HEIGHT = 450 | |
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, title) | |
ball_position = pyray.Vector2(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) | |
pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second | |
# Main game loop | |
while not pyray.window_should_close(): # Detect window close button or ESC key | |
# Update | |
if pyray.is_key_down(pyray.KEY_RIGHT): | |
ball_position.x += 2 | |
if pyray.is_key_down(pyray.KEY_LEFT): | |
ball_position.x -= 2 | |
if pyray.is_key_down(pyray.KEY_UP): | |
ball_position.y -= 2 | |
if pyray.is_key_down(pyray.KEY_DOWN): | |
ball_position.y += 2 | |
# Draw | |
pyray.begin_drawing() | |
pyray.clear_background(RAYWHITE) | |
pyray.draw_text('move the ball with arrow keys', 10, 10, 20, DARKGRAY) | |
pyray.draw_circle_v(ball_position, 50, MAROON) | |
pyray.end_drawing() | |
# De-Initialization | |
pyray.close_window() # Close window and OpenGL context | |
if __name__ == '__main__': | |
num_windows = 5 | |
processes = [] | |
for i_window in range(num_windows): | |
p = Process(target=launch_window, args=('window{}'.format(i_window),)) | |
processes.append(p) | |
p.start() | |
for p in processes: | |
p.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment