class AnimatedAmount
{
    constructor ( scene, x, y, bmFont, useUnits )
    {
		this.parent = scene;
		this.x = x;
		this.y = y;

		this.useUnits = useUnits;

		this.bmText = this.parent.add.bitmapText(x, y, bmFont, '');

		this.int_max = 4294967295;
		
		this.first_ = 0.0;
		this.last_ = this.int_max;
		this.t_ = 0.0;
		this.speed = 1200.0;
		
		this.visible = true;
		this.timer = 0;//for tweening
	}

	reset ( value )
	{
		this.first_ = parseFloat(value);
		this.last_ = value;
		this.t_ = 1.0;

		this.setText(value);
	}
	
	value ()
	{
		return Math.round( this.value2() );
	}
	
	value2 ()
	{
		if( this.last_ == this.int_max )
		{
			return this.first_;
		}
	
		var t = this.t_ - 2.0 * this.t_ * ( this.t_ - 0.5 ) * ( this.t_ - 1.0 );
	
		return this.first_ + t * ( this.last_ - this.first_ );
	}

	getTextBounds ()
	{
		return this.bmText.getTextBounds();
	}

	setAlpha ( v )
	{
		this.bmText.setAlpha( v );
	}

	setVisible ( v )
	{
		this.visible = v;
		this.bmText.setVisible( v );
	}

	setScale ( v )
	{
		this.bmText.setScale( v );
	}

	getScale()
	{
		return this.bmText.scale;
	}

	setSpacing ( v )
	{
		this.bmText.letterSpacing = v;
	}

	setPosition ( x, y )
	{
		this.x = x;
		this.y = y;

		this.bmText.x = x;
		this.bmText.y = y;
	}

	setOrigin ( v )
	{
		this.bmText.setOrigin(v);
	}

	setOriginXY ( v, w )
	{
		this.bmText.setOrigin(v, w);
	}

	setSpeed ( v ) 
	{
		if( v > 0 )
		{
			this.speed = v;//bigger the slower
		}			
	}

	setText ( v )
	{
		if(this.useUnits)
		{
			this.bmText.setText(v);
		}
		else
		{
			this.bmText.setText(parseFloat(v/100).toFixed(2));
		}
	}

	update ( delta, target )
    {
		if(!this.visible)
		{
			return;				
		}

		if( this.last_ == this.int_max )
		{
			this.reset( target );
			return;
		}

		if( this.last_ != target )
		{
			this.first_ = this.value2();
			this.last_ = target;
			this.t_ = 0.0;
		}

		this.t_ += delta / this.speed;

		if( this.t_ > 1.0 )
		{
			this.t_ = 1.0;
		}

		this.setText(this.value());
	}
}    
