Adding and Removing Behaviors
Behaviors are pre-defined sets of actions that a sprite can perform over and over. When a sprite begins a behavior you are telling the computer to run that set of actions on the sprite over and over until the behavior stops.
Behaviors can be added to and removed from sprites using sprite begins
, sprite stops
, and stops everything
. Sprites can have multiple behaviors at the same time and each behavior will continue until stopped.
Sprite lab provides some premade behaviors, but there is also an option to create a custom behavior. You can learn more about Defining Behaviors
.
Examples
A behavior has been created to make a sprite move northwest.
Tips
- Sprites must be created before they can be given a behavior.
- Behaviors can be given to individual sprites or groups of sprites (using the
costume
block). If a group is running a certain behavior(s), newly created sprites with the same costume will not automatically begin the behavior(s). - Connect
sprite stops
orstops everything
blocks to events likesprite clicked
. Code is executed quickly in Sprite Lab. If you tell a sprite to begin a behavior and then tell it to stop in the same sequence of code, there is not enough time to see the behavior in action.
Found a bug in the documentation? Let us know at support@code.org.