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) arcade.set_background_color(bg_color) self.width = width self.height = height self.title = title def on_draw(self): arcade.start_render() 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) arcade.run() if __name__ == '__main__': main()
- This time we pass another value into the constructor and store it on the instance.
- We are now storing width and height on the instance.
- Why? We are doing a calculation in
on_draw. We want to draw the text in the middle of the screen.
heightwere passed into the constructor but to be used in another method, need to be stored on the instance
Arcade makes it easy to do games. You write a method named
Arcade will call that method to do all the drawing.
- Put the text a third of the way from the top.