pip install PySDL2 python import sdl2 sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) window = sdl2.SDL_CreateWindow(b"Game Engine", sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED, 800, 600, 0) renderer = sdl2.SDL_CreateRenderer(window, -1, 0) running = True while running: event = sdl2.SDL_Event() while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == sdl2.SDL_QUIT: running = False sdl2.SDL_DestroyRenderer(renderer) sdl2.SDL_DestroyWindow(window) sdl2.SDL_Quit() python import sdl2 class GameEngine: def __init__(self, width, height): sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) self.window = sdl2.SDL_CreateWindow(b"Game Engine", sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED, width, height, 0) self.renderer = sdl2.SDL_CreateRenderer(self.window, -1, 0) def run(self): running = True while running: event = sdl2.SDL_Event() while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == sdl2.SDL_QUIT: running = False sdl2.SDL_RenderClear(self.renderer) sdl2.SDL_RenderPresent(self.renderer) sdl2.SDL_DestroyRenderer(self.renderer) sdl2.SDL_DestroyWindow(self.window) sdl2.SDL_Quit() game_engine = GameEngine(800, 600) game_engine.run()


上一篇:
下一篇:
切换中文