Behaviors are actions that you can assign to actors to control how they interact, move, and change appearance. Behaviors are used to add logic to your game to control what happens when some event occurs (such as when an actor collides with an object), to make the actor take some action (such as changing its speed) or to change an actor’s appearance, such as its size, image, color, or transparency. There are three types of behaviors:
- rules: these can be used when you want a certain behavior to take place only under specific conditions. For example, you may have a rule that says when a specific actor is clicked, then show this prompt. These are indicated by a [G] next to the behavior name.
- persistent behaviors: behaviors that continue to act on an actor continuously (unless placed in a rule whose conditions are no longer true). These are indicated by a [B] next to the behavior name.
- action behaviors: behaviors that occur once, and only repeat themselves if placed in a rule whose conditions become false, and then true again. These are indicated by an [A] next to the behavior name.
In this tutorial we’ll go through each of the Behaviors; later tutorials will provide additional details on specific Behaviors that are used more often. There are currently 36 Behaviors; we’ve grouped them by use for your reference. You can also see each of these behaviors listed in our glossary.
Accelerate: Use Accelerate to specify the rate and direction of acceleration for an actor. If the drag attribute or gravity is not also applied to an actor, acceleration will be continuously applied, increasing the actor’s speed until it reaches the maximum defined speed, if any. See also the “Accelerate Toward” behavior.
Accelerate Toward: Use Accelerate Toward to specify the rate of acceleration and the targeted location of an actor. Use the expression editor to specify a static or moving target position. If the drag attribute or gravity is not also applied to an actor, acceleration will be continuously applied, increasing the actor’s speed until it reaches the maximum defined speed, if any. The actor will continue accelerating past the target location along the existing trajectory unless slowed through other behaviors or attributes. See also the “Accelerate” behavior.
Add/Remove Row: This behavior allows the user to select a table, and add or remove rows from the selected table. “Action:” can be either Add Row/Remove Row, At Beginning/At End/At Index, if At Index is selected, then the expression field will be displayed which will then allow the user to select which index to use. If a row is add, it will shift everything above up by one at the location. If a row is removed, it will shift everything above down by one location. If the table data needs to be persisted, it will need to be saved by the save table behavior above.
Animate: Drag and drop a sequence of images into this behavior from your project library. Once added, images can be reordered, and additional images can be inserted. The controls in this behavior allow you to specify the frame rate of the animation, up to 30 frames per second; whether or not the animation loops, stops at the last frame, or returns to the last image used before the animate behavior started.
Buzz: Buzz phone if vibration is turned on.
Change Attribute: This behavior allows you to set, change, or increment a game, scene, or actor attribute. It can be used to change a numerical value, color, size, movement, acceleration, or any other value determined by an attribute.
Change Image: Specify an image to replace the current image on an actor. You can either drag the new image to this behavior or specify an image from the drop-down menu.
Change Scene: This behavior will stop the current scene and immediately move to the designated scene. It’s best to place this behavior inside a rule that changes to the game credits scene, menu scene, or to a new game level after certain objectives are met.
Change Size: This behavior changes an actor’s size by a scale factor (use a negative number to shrink an actor). Note: the actor’s original size will still determine its collision volume; to change this, use “change attribute” or “interpolate” instead. Use a timer to specify the amount of time that the transformation should take to occur.
Change Table Value: This behavior allows the user to select a table, then change multiple column values based on a single row. The user begins with one column selectable, and as columns are added they will begin to scroll when they reach 7. If the type is not allowed by the column or the reference data is wrong, it will be ignored by the function. The data will persist for the duration of the run. If the data is to be persisted, it will need to be saved using the save behavior described above.
Change Velocity: Specify the direction of movement for the actor at a constant designated speed. Once the direction is specified, other influences on movement will begin to affect the actor, such as drag, gravity, or other movement behaviors.
Collide: This behavior controls which actors or groups of actors will collide with each other. A group of actors may be created by using a tag in the project editor.
Constrain Attribute: This behavior continuously updates the value of one attribute to match another attribute. This is particularly useful to keep two objects moving in sync, or to keep an actor tied to the movement of the mouse or touch.
Control Camera: Add this behavior to an actor and the scene’s camera will scroll to follow. The tracking area for the camera can be changed in the Scene Editor using Camera Edit mode. Only one actor instance per scene can have this behavior; actors in non-scrollable layers cannot use the Control Camera behavior.
Copy Table: This behavior allows the user to select a source table as well as a destination table. This behavior will copy the specified table in it’s entirety to the target table. Meaning, no matter what the contents of the target table, it will be completely overwritten by the source table. If the source table is 4×5 and the target is 100×100, the target will be reformatted to 4×5 and all of its contents will be overwritten by the source table values.
Destroy: Immediately removes the actor from the scene.
Display Text: This behavior will show the text entered in the box, and includes controls over the color, alignment, font, wrapping, and size of the text displayed. Wrapping will cause line breaks in order to keep all of the text inside the actor.
Group: This is an organizational behavior, which allows you to group certain behaviors and rules together easily and clearly. It can also be created by selecting the “Create Group” button.
In App Purchase – Buy Item: Allows the player to purchase an item in app, which was setup on iTunes Connect or other 3rd party store service. Works with Apple iOS and Google Play for Pro users and Amazon Appstore on Kindle Fire.
In App Purchase – Consume Item: Flags a consumable item to have been consumed, so that the item can be bought again. Until this behavior is called, a purchased consumable item cannot be repurchased.
In App Purchase – Request Purchase Data: Retrieves item (or items) data from the store and fills in the Purchase Table with the data. Do not display purchase info for items until this behavior has been called. The data will be localized for the location of the player.
In App Purchase – Restore Items: Allows the player to refresh the state of all the items in the Purchase Table for your game. This should be called near the start of your game; you should also allow the player to do this manually.
Interpolate: This behavior allows you to change attributes from their existing value to a new value over a set period of time. Interpolate will use a constant rate of change over the designated time period. This behavior can effect a rapid or gradual change in any game attribute, and cannot be obstructed or stopped by any other behavior.
Keyboard Input: Enter text from the keyboard.
Load Attribute: Loads the value stored with a custom key name using the Save Attribute behavior. A key is basically a storage location for a specific attribute. Use any key you want when saving an attribute, and then use the same key to load that same information later.
Log Debugging Statement: Logs a statement in the debugging window.
Loop: Executes a group of behaviors repeatedly until a given condition is reached. Note: the following behaviors will not work in a loop: Accelerate, Accelerate Toward, Animate, Collide, Constrain Attribute, Control Camera, Display Text, Interpolate, Keyboard Input, Loop, Loop Table, Move, Move To, Particles, Play Sound, Replicate, Rotate, Rotate To Angle, Rotate to Position, Timer. A Rule may work in a loop as long as it only contains behaviors that will work in a loop.
Loop Over Table: Runs the same behaviors for each row or column in a table. The row or column index is stored in an attribute. Note: the following behaviors will not work in a loop: Accelerate, Accelerate Toward, Animate, Collide, Constrain Attribute, Control Camera, Display Text, Interpolate, Keyboard Input, Loop, Loop Table, Move, Move To, Particles, Play Sound, Replicate, Rotate, Rotate To Angle, Rotate to Position, Timer. A Rule may work in a loop as long as it only contains behaviors that will work in a loop.
Move: Use to move in a particular direction relative to the actor or the scene at a specified velocity. Additive movement allows multiple move behaviors to stack, or act on an actor simultaneously; Stacked movement causes only the most recent active movement behavior to control the actor.
Move to: Use to move towards a specific X/Y coordinate relative to the actor or to the scene. This movement will stop upon arrival at the designated coordinates unless the controlling conditions are no longer valid and “run to completion” is not checked, in which case the movement behavior will cease as soon as the controlling conditions are no longer valid.
Note: This behavior allows the developer to record reference notes explaining a rule, behavior, group, or other aspect of the game. These will not be visible in or affect the operation of the game.
Open URL: Specify a URL to open. The URL will open in an external window in the user’s default browser.
Particles: Spawns a designated number of particles from behind the actor. This behavior includes options for color, size, lifetime, velocity, images, and more.
Path Find: Run the A* pathfinder on a map table. The map table’s columns must be integers, with each cell giving the cost of entering the cell, or a negative number being impassible. The resulting path is stored in a table with two integer columns, giving the row and column of the path, or an empty table if there is no path.
Pause Game: This behavior will pause the current scene and display the scene selected in the behavior over the current scene. Using the “unpause game” behavior removes the scene and resumes the original scene.
Pause Music: This behavior will pause the currently music track, if one is playing. Use the “play music” behavior to resume the track.
Play Music: This behavior causes the selected music file to start playing. Select “loop” to cause the selected music to begin again once it has played through to the end.
Play Sound: This behavior causes the selected sound file to start playing. Select “loop” to cause the selected sound file to repeat each time it completes; select “run to completion” to prevent other behaviors from interrupting the sound before it has played through to the end. “Positional Sound” and “Velocity Shift” will affect the volume and pitch of the sound as the actor controlling the sound effect moves through the scene.
Replicate: This creates duplicates of an actor without actually spawning additional actors into a scene, based on the value of an attribute. It is most commonly used to display the number of lives a player has left.
Reset Game: Resets the game and all the scenes in it. This will restore all attribute values to their original state, but will not delete keys saved using the “Save Attribute” behavior.
Reset Scene: Resets the current scene and all the actors in it. If placed in the scene that appears during a pause, will not reset the underlying paused scene.
Rotate: Causes the actor to spin clockwise or counter-clockwise at the speed specified in the expression editor. The “rotate to angle” and “rotate to position” behaviors perform similar, but unique tasks.
Rotate to Angle: Causes the actor to spin clockwise or counter-clockwise at the speed specified until it reaches a particular angle, at which point rotation will cease. Unchecking “stops on destination” will cause this behavior to act similarly to the “rotate” behavior.
Rotate to Position: Causes the actor to spin clockwise or counter-clockwise at the speed specified until it reaches the designated X/Y coordinate, at which point rotation will cease. Unchecking “stops on destination” will cause this behavior to act similarly to the “rotate” behavior. Use “Offset Angle” to rotate to a position a designated number of degrees from the specified X/Y coordinate.
Rule: Creates a condition or set of conditions to check before activating an enclosed behavior. These conditions include player input (mouse clicks, touches, key presses) and attribute values. Rule also includes an “otherwise” section; behaviors placed here will trigger whenever the conditions in the Rule are not true.
Save Attribute: Stores the value of an attribute with a custom key name. Any key name can be used; inputting the key name in the “Load Attribute” behavior will yield the stored value. Saving a new attribute value with a previously used key name will result in overwriting any existing saved data. Values stored using ”Save Attribute” will remain accessible, even if the game or device is turned off.
Save Table: The behavior allows the user to select a table from the list of tables that have been created. This behavior will copy a local save file for the specified table. Currently there is one one save file per table, and each time it is saved, it overwrites the previous save file for that table. Reseting to the default values requires the Copy Table behavior.
Show Banner: Displays an advertisement banner over your game scene. Whether an ad is actually displayed may depend on network connectivity and inventory availability. The behavior does not guarantee that an ad will be shown, so design your scene with content to fill the ad area in case an ad is not available. The user can choose which type of advertisement to be shown on the banner. Note that iAd and AdMob don’t support resizing ads, so only the position option will affect the ad.
Show More Games: This action will show a list of more games from an ad network.
Spawn Actor: Creates a new actor instance in the scene. Specify which actor to spawn and the directional and position of that actor relative to the scene or spawning actor. This allows any actor in a scene to spawn additional actors anywhere else in the same scene. Newly-spawned actors will immediately begin following any movement or other behaviors associated with them.
Stop Music: This behavior stops the current music track. Unlike the “pause music” behavior, this behavior resets the track, so that a “play music” behavior acting afterwards will start the music track from the beginning.
Timer: This behavior allows you to activate behaviors or rules at specified intervals. All timer values are in seconds. “After” triggers the behavior or rule once after the given time period; “every” triggers the behavior repeatedly with a given delay between each trigger; “for” keeps a behavior active for the duration of the time.
Tweet Sheet: Allows the player to post a message and image to Twitter. Twitter messages are limited to 140 characters in length (119 characters in length with an image attachment).
Unpause Game: If the “pause game” behavior has activated and opened the pause scene, this behavior will remove the pause scene and resume the underlying paused scene.