HaxeFlixel Logo HaxeFlixel Snippets
  • About
  • Back to HaxeFlixel.com
    • Screen
    • Adding
    • Alive
    • Health
    • Making Sprites
    • Loading Sprites
    • Animation
    • Alpha
    • Color
    • Facing
    • Scale
    • Baked Rotations
    • FlxText
    • FlxBitmapText
    • Velocity
    • Acceleration
    • MaxVelocity
    • Gravity
    • Jumping
    • Angle
    • Angular Velocity
    • Angular Acceleration
    • Basic Group
    • Typed Group
    • Recycling
    • Sorting
    • Tileblock
    • Tilemap
    • Ray
    • tileProperties
    • Autotiles
    • Simple Overlap
    • Overlap Callbacks
    • 1-to-1 Collision
    • Immovable
    • Tilemap Collision
    • Moving Platforms
    • Flash
    • Fade
    • Shake
    • Follow
    • scrollFactor
    • Basics
    • Keyboard
    • Gamepad
    • Mouse
    • Button
    • FlxSound
    • FlxState
    • FlxSubState
    • Tween
    • Angle
    • Color
    • Motion
    • Num
    • Callbacks
    • FlxTimer
    • FlxSignal
    • moveTowards
    • Distance
    • velocityFromAngle
    • timeScale
    • drawLine

Tween

FlxTween can be used to change values over time following a number of available curve functions.

Using tween allows you to pass any kind of object, and several parameters that you want to tween over.

// create a tween
FlxTween.tween(myObject, {parameter: destinationValue}, duration, {type: tweenType, easing: FlxEase: easeFunction});

Demonstration

Source

View Source on GitHub

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;

class PlayState extends FlxState
{
	var sprite:FlxSprite;

	override public function create()
	{
		sprite = new FlxSprite("assets/sprite.png");
		sprite.x = sprite.y = 50;
		add(sprite);

		bgColor = 0;

		super.create();

		FlxTween.tween(sprite,
			{x: FlxG.width - sprite.width - 50, y: FlxG.height - sprite.height - 50, angle: 360},
			3, {type: FlxTweenType.PINGPONG, ease: FlxEase.sineInOut});
	}
}

Tags

tweens
Powered By HaxeFlixel Logo HaxeFlixel