03_views.py差异#
03_views.py#
--- /pb1/repo/arcade/doc/tutorials/views/02_views.py
+++ /pb1/repo/arcade/doc/tutorials/views/03_views.py
@@ -9,6 +9,32 @@
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Implement Views Example"
+
+
+class InstructionView(arcade.View):
+ """ View to show instructions """
+
+ def on_show_view(self):
+ """ This is run once when we switch to this view """
+ self.window.background_color = arcade.csscolor.DARK_SLATE_BLUE
+
+ # Reset the viewport, necessary if we have a scrolling game and we need
+ # to reset the viewport back to the start so we can see what we draw.
+ self.window.default_camera.use()
+
+ def on_draw(self):
+ """ Draw this view """
+ self.clear()
+ arcade.draw_text("Instructions Screen", self.window.width / 2, self.window.height / 2,
+ arcade.color.WHITE, font_size=50, anchor_x="center")
+ arcade.draw_text("Click to advance", self.window.width / 2, self.window.height / 2-75,
+ arcade.color.WHITE, font_size=20, anchor_x="center")
+
+ def on_mouse_press(self, _x, _y, _button, _modifiers):
+ """ If the user presses the mouse button, start the game. """
+ game_view = GameView()
+ game_view.setup()
+ self.window.show_view(game_view)
class GameView(arcade.View):
@@ -102,9 +128,8 @@
""" Main function """
window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
- start_view = GameView()
+ start_view = InstructionView()
window.show_view(start_view)
- start_view.setup()
arcade.run()