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
    • Mouse
    • Button
    • FlxSound
    • FlxState
    • FlxSubState
    • Tween
    • Angle
    • Color
    • Motion
    • Num
    • Callbacks
    • FlxTimer
    • FlxSignal
    • moveTowards
    • Distance
    • velocityFromAngle
    • timeScale
    • drawLine

Num

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

Using num allows you to change a numerical value over time, and pass the value to a function to use however you want.

// create a numeric tween
FlxTween.num(fromValue, toValue, duration, {type: tweenType, easing: FlxEase: easeFunction}, updateFunction);

private function updateFunction(Value:Float):Void
{
    // do something with the value
    console.log(Value);
}

Demonstration

Source

View Source on GitHub

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;

class PlayState extends FlxState
{
	var text:FlxText;

	override public function create()
	{
		text = new FlxText();
		text.text = "0";
		text.color = FlxColor.CYAN;
		text.size = 32;
		text.setBorderStyle(FlxTextBorderStyle.SHADOW, FlxColor.BLUE, 4);
		text.screenCenter();
		add(text);

		bgColor = 0;

		super.create();

		FlxTween.num(0, 100, 10, {type: FlxTweenType.PINGPONG, ease: FlxEase.quintIn}, updateValue);
	}

	private function updateValue(value:Float):Void
	{
		text.text = Std.string(Std.int(value));
	}
}

Tags

tweens
Powered By HaxeFlixel Logo HaxeFlixel