Animated Tiles
TpAnimatedTile
TpAnimatedTile is a simple animated tile and if you want to learn about the code, it’s the simplest TPT Tile.
Public fields:
- PlayOnStart: Begin animation when the game starts.
- AnimationSpeed: Set animation speed relative to that set in the Tilemap.
- OneShot: Play the animation once, then stop.
- Rewind After One Shot: if checked, after a one-shot animation, the animation rewinds to the first sprite.
- To return to the Tile’s sprite, use the ActivateAnimation method to turn off animation.
- Update Physics: see the description of this Tile Animation Flag in the Unity documentation.
- AnimatedSprites: A list of sprites to animate (use an Inspector on the Project asset).
Note that for TpAnimatedTile the static tile is the tile sprite. For TpFlexAnimatedTile the sprite specified by a clip’s DefaultTileIndex value is displayed. If that doesn’t work (it’s incorrect or the sprite is null) then the static tile is the tile sprite.
If painting this tile via script, see the FAQ entry “Animated tile not animating.”
TpFlexAnimatedTile
TpFlexAnimatedTile is an upgraded TpAnimatedTile that adds the ability to have multiple animation sequences contained in an asset file. Once placed, you can select on a per-tile basis which animation sequence is used initially, and several other settings, including whether to play automatically when the Scene is loaded, and which sequence is in use. When using many animated tiles, the use of an asset is more memory efficient than TpAnimatedTile.
The asset file for this tile is TpSpriteAnimationClipSet, and its fields are mostly the same as those for TpAnimatedTile. You can create it from the Assets/Create menu.
Public fields:
- PlayOnStart: Begin animation when the game starts, using the preset animation sequence.
- DefaultSprite: Sprite to display when nothing else is available, for example, a missing ClipSet asset.
- ClipSet: The TpSpriteAnimationClipSet asset from your Project folder.
- UseAnimationSpeedOverride: Don’t use the animation speed from the Clipset.
- AnimationSpeedOverride: Use this animation speed if UseAnimationSpeedOverride is checked.
- ForceOneShot: Ignore the OneShot setting in the ClipSet asset and always play one-shot animations.
- Rewind After One Shot: after a one-shot animation is completed the animation rewinds to the first image. Overrides the RewindAfterOneShot setting in the animation clip IF ForceOneShot is checked.
- To return to the Tile’s sprite, use the ActivateAnimation method to turn off animation.
- Update Physics: see the description of this Tile Animation Flag in the Unity documentation.
When inspecting one of these tiles using the Selection Inspector, you’ll see a dropdown Clip to use where you can select the animation sequence from the ClipSet to be used when your game starts. This can also be changed via code.
If painting this tile via script, see the FAQ entry “Animated tile not animating.”
TpSlideShow
TpSlideShow lets you display one Sprite at a time from a list of Sprites contained in an asset file. The initial Sprite to display can be changed, and you move from one Sprite to the next programmatically, with automatic wrapping or limiting, or set the displayed sprite directly.
Wrapping means that incrementing from the last slide returns to the first slide (or when decrementing, from the last slide to the first slide) and limiting means that incrementing from the last slide or decrementing from the first slide has no effect. This tile is used for the background in the BasicTiles demo.
The asset file for this tile is TpSlideShowSpriteSet, and its fields discussed in the Programmer’s Guide. You can create it from the Assets/Create menu.
Public fields:
- SlidesClipSet: The TpSlideShowSpriteSet asset from your Project folder.
- SlideShowAtStart: The name of the slide show to show when your game starts.
- WrappingOverride: Override the ‘wrap’ setting from the TpSlideShowSpriteSet asset.
- SlideIndexAtStart: is useful to set which slide is used when the app starts, and you can set this in the UI.
- CopyToSlideIndex: if checked, the ChangeSlide buttons copy the current slide index to SlideIndexAtStart.
- Convenience function useful when using only one slide show from a slide show sprite set.
- Trigger On Value Change: if checked, posts an Event when the slide changes.
- Accepts Clicks: if checked, accepts ActionToTile messages.
- Zone Capability: controls propogation of messages.
The last three features listed above are discussed here.
When inspecting one of these tiles using the Selection Inspector, you’ll see a dropdown where you can select which slideshow set from the TpSlideShowSpriteSet to be used at start. This can also be changed via code.
Technically, the SlideShow tile uses the Tilemap's animation system but the animation is always on pause. Changing slides changes the animation parameters but only one sprite (slide) is shown at a time.
AnimatedSpawner
Animated Spawner is a subclass of TpFlexAnimatedTile. It responds to ActionToTile packets via the Messaging system or one can directly call methods that will spawn a tile. All of the Animation methods of FlexAnimatedTile are of course available.
Public Fields:
- PrefabList: a reference to a PrefabList asset with the prefabs that might be spawned.
- SpawnMode: spawn prefabs in the order found in the PrefabList or spawn random prefabs from the asset.
- PositioningMode: how to position prefabs or tiles. UseAssetSetting uses info from asset. Any other ignores that info.
- KeepWorldPosition: Keep world position when a Prefab is spawned.
One might note that AnimatedSpawner and FlexAnimatedTile both have explicit declarations of MessageTargets (for the Messaging system) which take ActionToTile packets.
This shows the power of Explicit declarations: the MessageTarget in the FlexAnimatedTile superclass is ignored by the Messaging System because sending a message to an AnimatedSpawner instance is sent to the 'override' method with the highest level explict declaration. (oversimplification).