CMPT 166 Lecture Notes - Lecture 27: Arex, Source Code, Thx

55 views7 pages

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();

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents