CMPT 166 Lecture Notes - Lecture 27: Arex, Source Code, Thx
Document Summary
In these notes we"ll create a class for a rectangle that can move and spin. It"s a good example of how to go about creating your own animated sprites. We will need the sprite class: class sprite { float x; float y; float dx; float dy; void update() { x += dx; y += dy; Here is the spinningbox class, and its variables: class spinningbox extends sprite { float width; float height; float angleindegrees; float dangle; // rate of change of angle color fillcolor; color strokecolor; Recall that extends sprite means that a copy of all the variables and functions in the sprite class will be put in spinningbox. So, we don"t need to add x, y, dx, or dy because they are inherited from sprite. The render() function draws the box, while the update() function makes it move: void render() { rectmode(center); pushmatrix();