Custom-Sized Sprites!
Goals:
- Specify the dimensions of custom sprites
Coding Snippets:
- The Sprite constructor accepts a single string argument. However, this string can include multiple pieces of information. You can specify the sprite's color and/or its width and height.
Math and Computer Concepts:
- The quoted text in the snippets above is a data type called a string. Strings are used in coding to store and convey non-numeric as well as numeric information.
- It is essential to get the syntax for the Sprite constructor's string argument correct. For example, color must precede dimensions, and you must use a lower-case
x
, rather than*
orX
. Also, the dimensions are width×height, not the other way around, with no embedded spaces. - The order in which sprites are created determines which appears on top. If you create sprite B after sprite A, B will obscure A.
Activities:
Save each of the following in a folder called SpriteSizing.
- Create an OddBlocks program containing sprites in different sizes and shapes. Design the blocks so that they can ultimately fit together, without overlapping, like pieces in a puzzle. Then move them all into place!
- Code a Window script that begins by making a background of random dots. Create a giant, black sprite that covers the entire screen (and then some), then use
fill erase
to remove a paned window in the middle of it. Make the sprite move around to reveal a changing view of the background. - RingsInMotion: Create a program with multiple rings (each a sprite) spinning around a central point at different speeds, resulting in a constantly changing pattern:
- InsideSpiral: Create a spinning spiral sprite, similar to the one created in the previous lesson. But this time put a border around it, so you can't see where the spiral ends. Do this by adding a larger sprite on top of your spiral, with a round "framed window" in it.