Skip to main content

Tweening GameObjects

Intro

The TpTileTweener can also be used to tween GameObjects' Position, Rotation, Scale, or Color.

There's no equivalent 'Matrix' tween that can tween all of these at once although that's easy to accomplish with multiple concurrent tweens.

CreateGoTween is the most basic entry point for GameObject tweening:

public long CreateGoTween(GameObject?            gameObject,                             
                          Action<TpTween,float>? gameObjectAction,                       
                          TpEasingFunction.Ease    ease,                                 
                          float                    duration,                             
                          long                     sequenceId         = 0L,              
                          LoopType                 loopType           = LoopType.None,   
                          int                      numLoops           = -1,              
                          Action<TpTween>?         onFinished         = null,            
                          Action<TpTween, float>?  onRewindOrPingPong = null,            
                          Action<TpTween>?         onLoopEnded        = null,            
                          Action<TpTween, float>?  onUpdate           = null )           

This is very flexible: provide a target GameObject and an Action to modify same. The remaining parameters are the same as for TPT tile tweens: ease function, duration, etc.

One can also create a sequence and add GameObject tweens to the sequence just like with TPT tile tweens. However, one cannot mix GameObject and TPT tile tweens in the same sequence: you'll get a 0L return value, indicating an error.

There are also two higher-level methods with preset Actions: GameObjectTrs and GameObjectColor

GameObjectTrs allows transform-related GameObject tweens for the most common use: supply an enum value indicating which component (position, rotation, scale) to affect.

The startValue parameter is nullable. If this is null the current value for position, rotation, or scale is used as the starting value. If not null, the tween will initially set position, rotation, or scale to this value.

public long GameObjectTrs(GoEaseTrsTarget trsEaseTarget,                                    
                          GameObject              go,                                       
                          Vector3?                startValue,                               
                          Vector3                 endValue,                                 
                          float                   duration,                                 
                          TpEasingFunction.Ease   ease,                                     
                          long                    sequenceId         = 0L,                  
                          LoopType                loopType           = LoopType.None,       
                          int                     numLoops           = -1,                  
                          Action<TpTween>?        onFinished         = null,                
                          Action<TpTween, float>? onRewindOrPingPong = null,                
                          Action<TpTween>?        onLoopEnded        = null,                
                          Action<TpTween, float>? onUpdate           = null)                

GameObjectColor is for color tweening. The startValue parameter is evaluated in the same way: use the value if provided but if null use the current color value.

This method accomodates SpriteRenderers and Renderers. It will use the first one it finds in the GameObject or its children.

public long GameObjectColor(GameObject              go,                                   
                            Color?                startValue,                             
                            Color                 endValue,                               
                            float                   duration,                             
                            TpEasingFunction.Ease   ease,                                 
                            long                    sequenceId         = 0L,              
                            LoopType                loopType           = LoopType.None,   
                            int                     numLoops           = -1,              
                            Action<TpTween>?        onFinished         = null,            
                            Action<TpTween, float>? onRewindOrPingPong = null,            
                            Action<TpTween>?        onLoopEnded        = null,            
                            Action<TpTween, float>? onUpdate           = null)