Attributes and Program State
Attributes and Program State
Learning Objectives
•Understand how to track a player’s score, their health, or other numeric data using attributes: and to display it on screen.
•See how to add images to actors in GameSalad.
•Learn the difference between a game-level attribute and an actor-level attribute.
•Develop an understanding of the concept of program state.
To demonstrate the notion of attributes and program state, we’ll create a simple (very simple) game wherein a monkey chases a banana. Each time the monkey “gets” the banana by overlapping with it, a point will be earned.
You’ll need to download these images to your computer to get started:
Then follow this video to get started:
1 - Importing Images and Setting the Scene.mov
Now we want to track the number of times the monkey has “eaten” the banana by overlapping with it. Watch this video to see how to add an attribute to the monkey, and to make the attribute change when the monkey “eats” the banana:
2 - Earning Points for Eating Food.mov
If you followed the video above, you saw that the score is displayed directly on the monkey. This is not ideal, as in most games, the score is displayed at the top of the window. Let’s modify our game to display the score at the top of the window – we’ll need another actor:
3 - Creating a Display Score Actor.mov
Now we need to make the “Display Score” actor actually display they player’s score. Here’s how to do it – we need a game level attribute:
4 - Creating a Game Level Attribute.mov
What’s the bottom line? There are two types of attributes in GameSalad: game-level attributes and actor-level attributes.
Game-level attributes are accessible to (as you might expect) all actors in a game. Any actor can change the value of a game-level attribute – and any actor can display a game-level attribute.
Actor-level attributes can be changed and displayed only by the actor the attribute is a part of.
This can be illustrated as follows:
Tracking Player Scores