Adding and Removing Behaviors

Category: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.

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 or stops everything blocks to events like sprite 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 documentation@code.org