Object Attributes
- Sprite objects have attributes for the x and coordinates of its location and for the image that is displayed when draw
- The values for these attributes come from when the sprite object is created - a_sprite = sprite.Sprite(0, 0, 'sprite.gif')
- It is also possible to add attributes to an object
- For example, the speed of a sprite could be an attribute - def update_sprite(a_sprite): a_sprite.y += a_sprite.speed_y a_sprite.speed_y = 1 a_sprite = sprite.Sprite(0, 0, 'sprite.gif')
- This is useful for adding gravity, an acceleration - def update_sprite(a_sprite): a_sprite.speed_y += GRAVITY a_sprite.y += a_sprite.speed_y a_sprite = sprite.Sprite(0, 0, 'sprite.gif') a_sprite.speed_y = 0 while graphics.window_open(): graphics.clear() update_sprite(a_sprite) graphics.draw_sprite(a_sprite) graphics.wait()