Class Animation

Re-create the earlier “kinda not-really” animation section, this time with a class.


import arcade

class MyGame(arcade.Window):
    def __init__(self, width, height, title, bg_color):
        super().__init__(width, height, title)
        self.width = width
        self.height = height
        self.title = title

    def on_draw(self):
        x = self.width / 2
        y = self.height / 2
        arcade.draw_text(self.title, x, y, arcade.color.BLACK, 12)

def main():
    game1 = MyGame(600, 600, 'Drawing Example', arcade.color.WHEAT)

if __name__ == '__main__':


  1. This time we pass another value into the constructor and store it on the instance.
  2. We are now storing width and height on the instance.
  3. Why? We are doing a calculation in on_draw. We want to draw the text in the middle of the screen. width and height were passed into the constructor but to be used in another method, need to be stored on the instance self.

What Is on_draw?

Arcade makes it easy to do games. You write a method named on_draw and Arcade will call that method to do all the drawing.


  1. Put the text a third of the way from the top.