Render Tweening

Blitz3D Forums/Blitz3D Programming/Render Tweening

AngelOnFira(Posted 2014) [#1]
So I've been reading about render tweening, and how it works. You capture the world as it is, then move everything as necessary, then tween to add extra frames in an allotted amount of time.

I was wondering how you would go about implementing this in a game. If a player has the w key held down to go forwards, would you captureworld then over the next few frames move into it? As in using the tweening as a smoother transition over multiple frames?


Kryzon(Posted 2014) [#2]
Tweening is a trick to save on fixed-rate logic updates.
Each logic update changes the 'state' of your game: where every object in the game is located, their colour, size, physics etc.

It's faster to interpolate between states than computing new states.
Rather than updating your game logic with a very fast rate to produce a smoother experience with more game states (say, 60 logic updates per second), you update it with a slower rate (30, 25 frames etc.), producing states that are temporally farther apart.
Rendering is entirely separate from the logic update rate, and should be limited to the VSync of the system running the game - this is usually 60 FPS. Since the rendering would happen faster than the logic updates (meaning, you would be wastefully rendering the same frame more than once), you resort to interpolating to 'generate' more frames. In a way, something like sub-states of the game, with each sub-state being slightly different. This is what visually produces a smooth result.

The interpolation does not mind the input keys that might be held between states. It simply interpolates between the properties of objects from one state to the next.
What this means is, if the player has the 'W' key held down then in one state the object is in a certain position, and on the next state the object will have moved a certain amount.
The interpolation will take care of representing the object on different points of that trajectory.

The interpolation is, in a way, a type of logic update, but it is less costly to perform than actual logic updates.

- - - - -

You should only worry about implementing render-tweening if your game is very heavy on processing and rendering. When the game becomes slow, things will move slowly but smoothly.

Most of the time, with simpler games, limiting the updates and rendering to the same rate such as 30 FPS (used in several game consoles), is enough. When the game becomes slow, things will move in a stuttering manner.

I recommend the following articles:
- http://www.koonsolo.com/news/dewitters-gameloop/
- http://gafferongames.com/game-physics/fix-your-timestep/


Yue(Posted 2014) [#3]
While Not KeyHit(1)

	Repeat  :  elapsed = MilliSecs() - time  :  Until elapsed
	ticks = elapsed / period
	tween# = Float(elapsed Mod period) / Float(period)
	For k=1 To ticks
		time = time + period
		If k = ticks Then CaptureWorld
		UpdateObjects
		UpdateWorld
	Next
	UpdateShadows Camera, tween#				
	RenderWorld tween#

	Text 10, 10, FPS()
	Flip 0
Wend



Nexinarus(Posted 2014) [#4]
why not look at the castle demo that comes with blitz. Remove all the extra functions and code. Then i put all the functions i would use. It worked for me.

tweening in its simplest form is practically what Yue gave you above so i guess it would be kinda redundant to put the tweening code here too.