How to use the arcade.draw_text function in arcade

To help you get started, we’ve selected a few arcade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pvcraven / arcade / tests / unit2 / test_text.py View on Github external
def on_draw(self):
        arcade.start_render()
        current_x = 20

        # First line
        current_y = SCREEN_HEIGHT - LINE_HEIGHT
        arcade.draw_text("Test Text", current_x, current_y, arcade.color.BLACK, 12)

        # Again to test caching
        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text", current_x, current_y, arcade.color.BLACK, 12)

        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text Anchor Left", SCREEN_WIDTH // 2, current_y,
                         arcade.color.BLACK, 12, anchor_x="left")
        arcade.draw_point(SCREEN_WIDTH // 2, current_y, arcade.color.RED, 5)

        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text Anchor Center", SCREEN_WIDTH // 2, current_y,
                         arcade.color.BLACK, 12, anchor_x="center")
        arcade.draw_point(SCREEN_WIDTH // 2, current_y, arcade.color.RED, 5)

        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text Anchor Right", SCREEN_WIDTH // 2, current_y,
                         arcade.color.BLACK, 12, anchor_x="right")
        arcade.draw_point(SCREEN_WIDTH // 2, current_y, arcade.color.RED, 5)

        current_y -= LINE_HEIGHT
        arcade.draw_text("Test Text Anchor Top", SCREEN_WIDTH // 2, current_y,
                         arcade.color.BLACK, 12, anchor_y="top")
github pvcraven / arcade / tests / unit2 / run_map.py View on Github external
def on_draw(self):
        """ Render the screen. """

        # Clear the screen to the background color
        arcade.start_render()

        # Draw our sprites
        self.wall_list.draw()
        self.coin_list.draw()
        self.player_list.draw()

        # Draw our score on the screen, scrolling it with the viewport
        score_text = f"Score: {self.score}"
        arcade.draw_text(score_text, 10 + self.view_left, 10 + self.view_bottom,
                         arcade.csscolor.WHITE, 18)
github pvcraven / arcade / arcade / examples / perf_test / stress_test_collision_arcade.py View on Github external
def on_draw(self):
        """ Draw everything """

        # Start timing how long this takes
        draw_start_time = timeit.default_timer()

        arcade.start_render()
        self.coin_list.draw()
        self.player_list.draw()

        # Display info on sprites
        output = f"Sprite count: {len(self.coin_list):,}"
        arcade.draw_text(output, 20, SCREEN_HEIGHT - 20, arcade.color.BLACK, 16)

        # Display timings
        output = f"Processing time: {self.processing_time:.3f}"
        arcade.draw_text(output, 20, SCREEN_HEIGHT - 40, arcade.color.BLACK, 16)

        output = f"Drawing time: {self.draw_time:.3f}"
        arcade.draw_text(output, 20, SCREEN_HEIGHT - 60, arcade.color.BLACK, 16)

        fps = self.fps.get_fps()
        output = f"FPS: {fps:3.0f}"
        arcade.draw_text(output, 20, SCREEN_HEIGHT - 80, arcade.color.BLACK, 16)

        self.draw_time = timeit.default_timer() - draw_start_time
        self.fps.tick()
github pvcraven / arcade_book / source / chapters / 21_shooting_sprites / sprites_bullet_02.py View on Github external
def on_draw(self):
        """
        Render the screen.
        """

        # This command has to happen before we start drawing
        arcade.start_render()

        # Draw all the sprites.
        self.coin_list.draw()
        self.player_list.draw()
        self.bullet_list.draw()

        # Render the text
        arcade.draw_text(f"Score: {self.score}", 10, 20, arcade.color.WHITE, 14)
github pvcraven / arcade / arcade / examples / view_instructions_and_game_over.py View on Github external
def on_draw(self):
        arcade.start_render()
        """
        Draw "Game over" across the screen.
        """
        arcade.draw_text("Game Over", 240, 400, arcade.color.WHITE, 54)
        arcade.draw_text("Click to restart", 310, 300, arcade.color.WHITE, 24)

        time_taken_formatted = f"{round(self.time_taken, 2)} seconds"
        arcade.draw_text(f"Time taken: {time_taken_formatted}",
                         WIDTH/2,
                         200,
                         arcade.color.GRAY,
                         font_size=15,
                         anchor_x="center")

        output_total = f"Total Score: {self.window.total_score}"
        arcade.draw_text(output_total, 10, 10, arcade.color.WHITE, 14)
github pvcraven / arcade / examples / drawing_text.py View on Github external
arcade.draw_point(start_x, start_y, arcade.color.BLUE, 5)
        start_x = 50
        start_y = 400
        arcade.draw_text("Text anchored 'top' and 'left'.",
                         start_x, start_y, arcade.color.BLACK, 12, anchor_x="left", anchor_y="top")

        start_y = 350
        arcade.draw_point(start_x, start_y, arcade.color.BLUE, 5)
        arcade.draw_text("14 point multi\nline\ntext",
                         start_x, start_y, arcade.color.BLACK, 14, anchor_y="top")

        start_y = 450
        start_x = 300
        arcade.draw_point(start_x, start_y, arcade.color.BLUE, 5)
        arcade.draw_text("Set of text\nthat\nis centered.",
                         start_x, start_y, arcade.color.BLACK, 14, width=200, align="center", anchor_y="top")

        start_y = 250
        start_x = 300
        arcade.draw_point(start_x, start_y, arcade.color.BLUE, 5)
        arcade.draw_text("Text centered on\na point",
                         start_x, start_y, arcade.color.BLACK, 14, width=200, align="center",
                         anchor_x="center", anchor_y="center")

        start_y = 150
        start_x = 300
        arcade.draw_point(start_x, start_y, arcade.color.BLUE, 5)
        arcade.draw_text("Text rotated on\na point", start_x, start_y,
                         arcade.color.BLACK, 14, width=200, align="center", anchor_x="center",
                         anchor_y="center", rotation=self.text_angle)
github akmalhakimi1991 / python-knife-hit / knifehit / gamemanager.py View on Github external
# Draw logo
        self.logo_list = arcade.SpriteList()
        self.logo = arcade.Sprite(self.GAME_CONFIG["assets_path"]["images"]["logo"], 0.5)
        self.logo.center_x = self.SCREEN_WIDTH*0.5
        self.logo.center_y = self.SCREEN_HEIGHT*0.6
        self.logo_list.append(self.logo)
        self.logo_list.draw()

        # Display "Game Over" text
        # output = "Python Knife Hit"
        # arcade.draw_text(output, self.SCREEN_WIDTH*0.5, self.SCREEN_HEIGHT*0.6, arcade.color.WHITE, 54,  align="center", anchor_x="center")

        # Display restart instruction
        output = "Press  To Start"
        arcade.draw_text(output, self.SCREEN_WIDTH*0.5, self.SCREEN_HEIGHT*0.35, arcade.color.WHITE, 24,  align="center", anchor_x="center")
github pvcraven / arcade_book / source / chapters / 05_drawing / draw_02.py View on Github external
arcade.draw_circle_filled(500, 550, 40, arcade.color.YELLOW)

# Rays to the left, right, up, and down
arcade.draw_line(500, 550, 400, 550, arcade.color.YELLOW, 3)
arcade.draw_line(500, 550, 600, 550, arcade.color.YELLOW, 3)
arcade.draw_line(500, 550, 500, 450, arcade.color.YELLOW, 3)
arcade.draw_line(500, 550, 500, 650, arcade.color.YELLOW, 3)

# Diagonal rays
arcade.draw_line(500, 550, 550, 600, arcade.color.YELLOW, 3)
arcade.draw_line(500, 550, 550, 500, arcade.color.YELLOW, 3)
arcade.draw_line(500, 550, 450, 600, arcade.color.YELLOW, 3)
arcade.draw_line(500, 550, 450, 500, arcade.color.YELLOW, 3)

# Draw text at (150, 230) with a font size of 24 pts.
arcade.draw_text("Arbor Day - Plant a Tree!",
                 150, 230,
                 arcade.color.BLACK, 24)

# Finish drawing
arcade.finish_render()

# Keep the window up until someone closes it.
arcade.run()
github pvcraven / arcade / arcade / examples / procedural_caves_cellular.py View on Github external
# Start timing how long this takes
        draw_start_time = timeit.default_timer()

        # This command should happen before we start drawing. It will clear
        # the screen to the background color, and erase what we drew last frame.
        arcade.start_render()

        # Draw the sprites
        self.wall_list.draw()
        self.player_list.draw()

        # Draw info on the screen
        sprite_count = len(self.wall_list)

        output = f"Sprite Count: {sprite_count}"
        arcade.draw_text(output,
                         self.view_left + 20,
                         self.height - 20 + self.view_bottom,
                         arcade.color.WHITE, 16)

        output = f"Drawing time: {self.draw_time:.3f}"
        arcade.draw_text(output,
                         self.view_left + 20,
                         self.height - 40 + self.view_bottom,
                         arcade.color.WHITE, 16)

        output = f"Processing time: {self.processing_time:.3f}"
        arcade.draw_text(output,
                         self.view_left + 20,
                         self.height - 60 + self.view_bottom,
                         arcade.color.WHITE, 16)
github pvcraven / arcade / arcade / examples / view_instructions_and_game_over.py View on Github external
def on_draw(self):
        arcade.start_render()
        # Draw all the sprites.
        self.player_list.draw()
        self.coin_list.draw()

        # Put the text on the screen.
        output = f"Score: {self.score}"
        arcade.draw_text(output, 10, 30, arcade.color.WHITE, 14)
        output_total = f"Total Score: {self.window.total_score}"
        arcade.draw_text(output_total, 10, 10, arcade.color.WHITE, 14)