Using Costumes in Scratch

A world of faces at your command

A health bar uses a different image for each state. The spaceship has a health of 10, so each possible value uses a different costume.

One of the most powerful features in Scratch is the costume editor. You can use this editor to create original content, but it is generally better to use an outside program where you have more powerful tools and more control. In my case, I used Inkscape to create my sprite images.

The Space Octopus alternates between two separate costumes to create the illusion of movement when animated.

Each sprite in scratch can hold up to 300 costumes, which can be used in a variety of ways by switching between them. A simple use of this technique is the animation for the space octopus enemies, which uses the "Switch Costume" block and the "Wait" block to create a simple animation of the octopus flexing its tentacles.

Another way to use this ability to switch costumes is to connect the costume name to a variable.I wanted to give my spaceship an HP bar that would go down as the ship took damage from space octopus attacks. To do this, I created a series of HP meter graphics in inkscape, ranging from 10 bars to zero bars.

The costumes were all stored in a sprite called HUD (For Heads Up Display) and I used a "Forever" loop block to make sure the program was constantly checking to see which costume to change to. I numbered the costumes 0-10 and used a "join" operator to connect the prefix of each of the costume names to a sensor that kept track of the ships Health Points variable.

In the above image, you can see that the blocks within the "Forever" block set the size to half the original size, sends the sprite to the front of all other sprites, and constantly switches the costume. Within the "Join" operator block the prefix "SOA-HP_" is connected to a sensor block that tracks the ShipHP of the Player sprite. Whenever the ShipHP number changes as a result of enemy damage or a power-up, the costume changes to the correct number of bars. The blue motion block tells the HP bar to always go to a location in the upper left hand corner.

You can see the health bar as well as the Space Octopus animations using costume changes by playing Space Octopus Attack 2.1 below!