Created
February 14, 2026 15:49
-
-
Save dfbarrero/17aea7bc1377b54729eb31d91ac97815 to your computer and use it in GitHub Desktop.
Example taken from https://learn.arcade.academy/en/latest/chapters/19_user_control/user_control.html
This file contains hidden or 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 arcade | |
| SCREEN_WIDTH = 640 | |
| SCREEN_HEIGHT = 480 | |
| class Ball: | |
| def __init__(self, position_x, position_y, radius, color): | |
| # Take the parameters of the init function above, | |
| # and create instance variables out of them. | |
| self.position_x = position_x | |
| self.position_y = position_y | |
| self.radius = radius | |
| self.color = color | |
| def draw(self): | |
| """ Draw the balls with the instance variables we have. """ | |
| arcade.draw_circle_filled(self.position_x, | |
| self.position_y, | |
| self.radius, | |
| self.color) | |
| class MyGame(arcade.Window): | |
| def __init__(self, width, height, title): | |
| # Call the parent class's init function | |
| super().__init__(width, height, title) | |
| # Make the mouse disappear when it is over the window. | |
| # So we just see our object, not the pointer. | |
| self.set_mouse_visible(False) | |
| arcade.set_background_color(arcade.color.ASH_GREY) | |
| # Create our ball | |
| self.ball = Ball(50, 50, 15, arcade.color.AUBURN) | |
| def on_draw(self): | |
| """ Called whenever we need to draw the window. """ | |
| self.clear() | |
| self.ball.draw() | |
| def on_mouse_motion(self, x, y, dx, dy): | |
| """ Called to update our objects. | |
| Happens approximately 60 times per second.""" | |
| self.ball.position_x = x | |
| self.ball.position_y = y | |
| def main(): | |
| window = MyGame(640, 480, "Drawing Example") | |
| arcade.run() | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment