rigz.tweener: | Types | Modinfo | Source |
tTweener | The tweener type. |
Type tTweener | |
Description | The tweener type. |
Information | By 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) | |
Returns | a new tTweener object. |
Description | Create a tweener. |
Information | Pass the frequency that you want your app to update every second. 30 = 30 updates per second. |
Method GetFps:Int() | |
Description | Get the current FPS. |
Method getFrameTicks:Int() | |
Description | Get the current number of frame ticks. |
Information | this gets the current number of frames you need to update for your for..next loop. |
Method getTween:Float() | |
Description | Get the current tween value. |
Information | You need the tween value to know how much you need to interpolate between old and new positions. |
Method GetUpdateFrequency:Double() | |
Description | Get the UpdateFrequency value in this tTweener object. |
Method GetUpdateTime:Double() | |
Description | Get the UpdateTime value in this tTweener object. |
Method SetUpdateFrequency(Value:Double) | |
Description | Set the UpdateFrequency value for this tTweener object. |
Method SetUpdateTime(Value:Double) | |
Description | Set the UpdateTime value for this tTweener object. |
Method Update() | |
Description | Update the tweener. |
Information | This 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() | |
Description | Keep a track of the execution time. |
Information | This command needs to be called inside the logic update loop. |
Function TweenValues:Float(oldValue:Float, value:Float, tween:Float) | |
Returns | The interpolated value. |
Description | Interpolate between 2 values. |
Information | You can use this function to find out where something should be drawn based on its old and new positions. |
Author | Peter J. Rigby |
---|---|
Copyright | Peter J. Rigby 2009 |
Purpose | Easily implement fixed rate timing code to your apps/games |
Version | v1.0 |
History v1.03 | Added GetTween now returns tween like it's supposed to! |
History v1.02 | Added GetFps() Method for finding out the current FPS of the game/app using it |
History v1.01 | Fixed create method so it now returns self - thanks redspark! |
History v1.00 | 11th April 2009 - Initial Version |