rigz.tweener: Types Modinfo Source  

Fixed timing object for tweening animation

Types Summary

tTweener The tweener type.

Types

Type tTweener
DescriptionThe tweener type.
InformationBy creating a tweener you can use it to control how many frames per second your game/app logic updates but let the stuff on screen be drawn as many times as possible, interpolating between each position to get very smooth results.
Example
SuperStrict

Import rigz.Tweener

SetGraphicsDriver GLMax2DDriver()

Graphics (800, 600, 0)

Global Tweener:tTweener = New tTweener.Create(10)

'A little test oval we can move about the screen
Type Testoval
	Field x:Float
	Field oldx:Float
	
	'The speed should be measured in pixels per second as the number will be divided be the current updatetime.
	Field speed:Float = 200
	
	Method Create:Testoval()
		Return New Testoval
	End Method
	
	Method update()
		'capture the old coordinate so that we have something to tween with
		capture()
		'divide the speed by the updatefrequency to get the proper pixels per second value and update x
		X:+speed / Tweener.UpdateFrequency
		'Bounce the oval off the side of the screens
		If x > GraphicsWidth() speed = -speed
		If x < 0 speed = -speed
	End Method
	
	'render the oval
	Method Render(tween:Float)
		'work out the interpolated position using the tweenvalues function in the tweener
		Local TweenedX:Float = Tweener.TweenValues(oldX, X, tween)
		'draw the tweened oval
		DrawOval TweenedX - 10, 200 - 25, 50, 50
		'and draw and untweened oval for comparison
		DrawOval X - 10, 300 - 25, 50, 50
	End Method
	
	'method to capture the old coordinates
	Method capture()
		oldx = x
	End Method
End Type

Local oval:Testoval = New Testoval.Create()

'Our main loop
While Not KeyDown(KEY_ESCAPE)
	
	Cls
		
	'here is the timing code, update the tweener to get the number of ticks for this loop
	Tweener.Update()
	
	For Local Ticks:Int = 1 To Tweener.FrameTicks
		'Update the execution time for the tweener
		Tweener.UpdateExecutionTime()
		oval.update()
	Next
	
	'Draw the oval
	oval.Render(Tweener.Tween)
		
	Flip 0
	
Wend
Methods Summary
Create Create a tweener.
GetFps Get the current FPS.
getFrameTicks Get the current number of frame ticks.
getTween Get the current tween value.
GetUpdateFrequency Get the UpdateFrequency value in this tTweener object.
GetUpdateTime Get the UpdateTime value in this tTweener object.
SetUpdateFrequency Set the UpdateFrequency value for this tTweener object.
SetUpdateTime Set the UpdateTime value for this tTweener object.
Update Update the tweener.
UpdateExecutionTime Keep a track of the execution time.
Functions Summary
TweenValues Interpolate between 2 values.
Method Create:tTweener(_UpdateFrequency:Float)
Returnsa new tTweener object.
DescriptionCreate a tweener.
InformationPass the frequency that you want your app to update every second. 30 = 30 updates per second.
Method GetFps:Int()
DescriptionGet the current FPS.
Method getFrameTicks:Int()
DescriptionGet the current number of frame ticks.
Informationthis gets the current number of frames you need to update for your for..next loop.
Method getTween:Float()
DescriptionGet the current tween value.
InformationYou need the tween value to know how much you need to interpolate between old and new positions.
Method GetUpdateFrequency:Double()
DescriptionGet the UpdateFrequency value in this tTweener object.
Method GetUpdateTime:Double()
DescriptionGet the UpdateTime value in this tTweener object.
Method SetUpdateFrequency(Value:Double)
DescriptionSet the UpdateFrequency value for this tTweener object.
Method SetUpdateTime(Value:Double)
DescriptionSet the UpdateTime value for this tTweener object.
Method Update()
DescriptionUpdate the tweener.
InformationThis needs to be called just before the logic update loop. It basically calculates how many logic updates need to be made this frame, if at all.
Method UpdateExecutionTime()
DescriptionKeep a track of the execution time.
InformationThis command needs to be called inside the logic update loop.
Function TweenValues:Float(oldValue:Float, value:Float, tween:Float)
ReturnsThe interpolated value.
DescriptionInterpolate between 2 values.
InformationYou can use this function to find out where something should be drawn based on its old and new positions.

Module Information

AuthorPeter J. Rigby
CopyrightPeter J. Rigby 2009
PurposeEasily implement fixed rate timing code to your apps/games
Versionv1.0
History v1.03Added GetTween now returns tween like it's supposed to!
History v1.02Added GetFps() Method for finding out the current FPS of the game/app using it
History v1.01Fixed create method so it now returns self - thanks redspark!
History v1.0011th April 2009 - Initial Version