TweenLogic

Provides functions for Tween.

# Methods

[{"index":"float Ease(float startValue, float endValue, float duration, EaseType type, float tweenTime)","0":"Interpolates between the start and end values. Interpolates tweenTime divided by duration. Returns endValue if duration is 0. May return unexpected values if tweenTime is less than 0 or greater than duration."}]

[{"index":"Tweener MakeNativeTween(float startValue, float endValue, float duration, EaseType type, Component targetComponent, string methodName)","0":"Creates a Tweener entity that automatically calls a native component's method and performs the interpolation between the start value and end value. Only the native component can be set as targetComponent. A void method type that receives one float as a parameter from the target component must be set for methodName. It's more effective than using MakeTween()."}]

[{"index":"Tweener MakeTween(float startValue, float endValue, float duration, EaseType type, func tweenFunction)","0":"Creates a Tweener Entity performing the interpolation between the start and end values."}]

[{"index":"Tweener MakeTween(Vector2 startValue, Vector2 endValue, float duration, EaseType type, func tweenFunction)","0":"Creates a Tweener Entity performing the interpolation between the start and end values."}]

[{"index":"Tweener MakeTween(Vector3 startValue, Vector3 endValue, float duration, EaseType type, func tweenFunction)","0":"Creates a Tweener Entity performing the interpolation between the start and end values."}]

[{"index":"Tweener MoveOffset(Entity entity, Vector2 offset, float duration, EaseType type)","0":"Creates and plays the Tweener that moves the entity as much as offset based on the current location."}]

[{"index":"Tweener MoveTo(Entity entity, Vector2 destination, float duration, EaseType type)","0":"Creates and plays the Tweener that moves the entity to the destination."}]

[{"index":"Tweener PlayTween(float startValue, float endValue, float duration, EaseType type, func tweenFunction)","0":"Creates and plays the Tweener entity performing the interpolation between the start and end values. Tweener sets the interpolated value as a parameter and calls tweenFunction."}]

[{"index":"Tweener PlayTween(Vector2 startValue, Vector2 endValue, float duration, EaseType type, func tweenFunction)","0":"Creates and plays the Tweener entity performing the interpolation between the start and end values. Tweener sets the interpolated value as a parameter and calls tweenFunction."}]

[{"index":"Tweener PlayTween(Vector3 startValue, Vector3 endValue, float duration, EaseType type, func tweenFunction)","0":"Creates and plays the Tweener entity performing the interpolation between the start and end values. Tweener sets the interpolated value as a parameter and calls tweenFunction."}]

[{"index":"Tweener RotateAroundOffset(Entity entity, float angle, Vector2 offset, boolean lookOffset, float duration, EaseType type)","0":"Creates and plays the Tweener, which rotates the entity counterclockwise as much as the angle on the offset axis."}]

[{"index":"Tweener RotateTo(Entity entity, float angle, float duration, EaseType type)","0":"Creates and plays the Tweener, which rotates the entity counterclockwise as much as the angle."}]

[{"index":"Tweener ScaleTo(Entity entity, Vector2 targetScale, float duration, EaseType type)","0":"Creates and plays the Tweener, which enlarges or reduces the entity as much as targetScale."}]

##### inherited from Logic:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the key-type event and its handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Examples

#### MoveOffset

This is an example of implementing movement using the MoveOffset() function.
    
    
    @Component
    script StartOffsetTween extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
        _TweenLogic:MoveOffset(self.Entity, Vector2(6,0), 6, EaseType.QuartEaseIn)
        end
    end
    

#### PlayTween

This is an example of implementing movement using the PlayTween() function.
    
    
    @Component
    script HorizontalMover extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
        local originalPosition = self.Entity.TransformComponent.Position
        local tweenCallback = function (tweenValue)
        	self.Entity.TransformComponent.Position = originalPosition + tweenValue:ToVector3()
        end
        _TweenLogic:PlayTween(Vector2(0,0), Vector2(6,0), 6, EaseType.QuartEaseIn, tweenCallback)
        end
    end
    

#### Ease

This is an example of implementing movement using the Ease() function.
    
    
    @Component
    script HorizontalTween extends Component
        method void OnBeginPlay()
        self._T.originalPosition = self.Entity.TransformComponent.Position
        self._T.elapsedTime = 0
        self._T.tweenDuration = 6
        self._T.isTweening = true
        end
    
        @ExecSpace("ServerOnly")
        method void OnUpdate(number delta)
        if not self._T.isTweening then
        	return
        end
    
        self._T.elapsedTime = self._T.elapsedTime + delta
        if self._T.elapsedTime > self._T.tweenDuration then
        	self._T.elapsedTime = self._T.tweenDuration
        	self._T.isTweening = false
        end
    
        local vectorX = _TweenLogic:Ease(0, 6, self._T.tweenDuration, EaseType.QuartEaseIn, self._T.elapsedTime)
        self.Entity.TransformComponent.Position = self._T.originalPosition + Vector3(vectorX, 0, 0)
        end
    end
    

#### MakeNativeTween()

This an example of using the SpriteRendererComponent SetAlpha() function by utilizing the MakeNativeTween() function.
    
    
    @Component
    script SpriteFadeOut extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
            local tweener = _TweenLogic:MakeNativeTween(1, 0, 3, EaseType.Linear, self.Entity.SpriteRendererComponent, "SetAlpha")
            tweener:Play()
        end
    end
    

# SeeAlso

  * TransformComponent
  * EaseType
  * [Entity Control Using TweenLogic](/docs?postId=746)