""" 演示如何处理屏幕缩放 If Python and Arcade are installed, this example can be run from the command line with: python -m arcade.examples.resizable_window """ import arcade SCREEN_WIDTH = 500 SCREEN_HEIGHT = 500 SCREEN_TITLE = "arcade街机模块演示如何处理屏幕缩放" START = 0 END = 2000 STEP = 50 class MyGame(arcade.Window): """ Main application class. """ def __init__(self, width, height, title): super().__init__(width, height, title, resizable=True) arcade.set_background_color(arcade.color.WHITE) def on_resize(self, width, height): """ 当窗口缩放时此函数会自动调用 """ # Call the parent. Failing to do this will mess up the coordinates, and default to 0,0 at the center and the # edges being -1 to 1. super().on_resize(width, height) print(f"Window resized to: {width}, {height}") def on_draw(self): """ 重画整个屏幕. """ arcade.start_render() # 从下到上画y标签 i = 0 for y in range(START, END, STEP): arcade.draw_point(0, y, arcade.color.RED, 5) arcade.draw_text(f"{y}", 5, y, arcade.color.BLACK, 12, anchor_x="left", anchor_y="bottom") i += 1 # 从左到右画x标签. i = 1 for x in range(START + STEP, END, STEP): arcade.draw_point(x, 0, arcade.color.BLUE, 5) arcade.draw_text(f"{x}", x, 5, arcade.color.BLACK, 12, anchor_x="left", anchor_y="bottom") i += 1 def main(): MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) arcade.run() if __name__ == "__main__": main()