Code archives/3D Graphics - Misc/RenderTween Easymode
This code has been declared by its author to be Public Domain code.
Download source code
|Include this in your project and have tweening added with one function call. Simply have your game logic all called from your own UpdateGame() function. In your mainloop call CheckTween() and thats it. You set the FPS in the include files CONST GAMEFPS. Copied from Marks code. Ive reused it several times as an include.|
;to use this as in include.. you must make youre main game loop in a function called updategame() ;so you call checktween() and inside checktween it calls updategame() for your game logic ;Include ;example main program Include "tween.bb" Graphics3D 800,600,0,2 Camera=CreateCamera() Global Box=CreateCube() PositionEntity camera,0,10,-10 PointEntity camera,box PositionEntity Box,0,0,3 While Not KeyDown(1) CheckTween() RenderWorld (frametween) Flip Wend Function UpdateGame() MoveEntity Box,0,0,.2 TurnEntity Box,0,.5,0 End Function ;end main code example ;include code : tween.bb ;tween.bb Global gameFPS = 60 ;your logic frames per second.. rendering will happen as fast as it can Global Frameperiod,Frametime,frameticks framePeriod = 1000 / gameFPS frameTime = MilliSecs () - framePeriod Function checktween() Repeat frameElapsed = MilliSecs () - frameTime Until frameElapsed frameTicks = frameElapsed / framePeriod frameTween# = Float (frameElapsed Mod framePeriod) / Float (framePeriod) If frameTicks>7 Then frameTicks=7:frametime=MilliSecs() For frameLimit = 1 To frameTicks Updategame() UpdateWorld() If frameLimit = frameTicks Then CaptureWorld() frameTime = frameTime + framePeriod Next End Function
| Nice idea |
| hi, i trying to understand this code, what is the basic concept?|
no more than x amount of renderworld depending on the fps?, but the updategame() "all game data" run more times than the renderworld?
| yes, updategame will happen x frames per second. While renderworld will happen as many times as possible without lowing Game Logic below desired FPS. Rendered with a tween value between frames , so it will be smooth as possible. |
| What's the significance of '7' ?|
If frameticks>7 Then frameticks=7:Frametime=MilliSecs()
| frameTicks = frameElapsed / framePeriod|
7 is from what I gather, the optimal deadzone value to check against. Ive tried to change it and the results werent any good.
| Ive used tweening before again using the layout from the "castle.bb" that came with blitz3d. I still prefer using it in the main loop the way it originally was in the example, but thats just me. That is why I made a tweening bb and backed it up for future projects and examples Thats good enough for me. |
Sorry for straying off course
My point is having it in a function is a cool idea but noobies could easily run into complications with variables. But then again I guess thats what types and arrays and globals are for.
To each their own. But I do think it is a cool idea. And if it works for you... All the power to you.
| That was sort of pointless.. |
Code Archives Forum