Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'FRLRT
- SuperStrict
- AppTitle$ = "Fixed Rate Logic with Render Tweening"
- Graphics 800,600
- Local newTime:Int = MilliSecs()
- Local oldtime:Int = newTime
- Local dt# = 1000 / 60 '100 FPS logic
- Local deltaTime#, accumulator#, alpha#, t#
- global CurrentvPosX:int = 40;
- global CurrentvPosY:int = 50;
- global PrevvPosX:int = 40;
- global PrevvPosY:int = 50;
- global CurrentVelX:int = 2;
- global CurrentVelY:int = 2;
- SetBlend ALPHABLEND
- Global imgBall:TImage = LoadImage("ball.png")
- MidHandleImage imgBall
- Global RenderTween:Int = False
- While Not KeyHit(KEY_ESCAPE)
- Cls
- newTime = MilliSecs()
- deltaTime# = (newTime - oldTime)
- oldTime = newTime
- accumulator :+ deltaTime
- While accumulator >= dt
- PrevvPosX = CurrentvPosX
- PrevvPosY = CurrentvPosY
- CurrentvPosX = CurrentvPosX + CurrentVelX
- CurrentvPosY = CurrentvPosY + CurrentVelY
- If CurrentvPosY <= 0 Or CurrentvPosY >= 600
- CurrentVelY = -CurrentVelY
- EndIf
- If CurrentvPosX <= 0 Or CurrentvPosX >= 800
- CurrentVelX = -CurrentVelX
- EndIf
- accumulator :- dt
- Wend
- alpha = accumulator / dt
- Local tx#, ty#
- If RenderTween
- tx# = CurrentvPosX * alpha + PrevvPosX * (1.0 - alpha)
- ty# = CurrentvPosY * alpha + PrevvPosY * (1.0 - alpha)
- Else
- tx# = CurrentvPosX
- ty# = CurrentvPosY
- EndIf
- DrawImage imgBall, tx#, ty#
- If KeyHit(KEY_SPACE) Then RenderTween = 1 - RenderTween
- DrawText "RenderTween: "+RenderTween,5,50
- Flip 1
- Wend
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement