Pause an animation?

Blitz3D Forums/Blitz3D Programming/Pause an animation?

fall_x(Posted 2004) [#1]
Hi,

In my game I'm making, sometimes I need to open a menu. In this menu, it is necessary to still call updateworld because things can change, however all animations should be stopped because the game is paused when the menu is open.

I think I can stop the animation with SetAnimTime entity,AnimTime(entity), but how do I restart it at the correct speed (because my entities animate at different speeds)? And can I loop trough all entities somehow? Or do I need to loop trough all my types that have entities?

Maybe a "wrapper-type" would do the trick, PauseableEntity, that contains the entity and the speed it was moving at, but reprogramming my entire game to use this would take too long.

Any ideas?

Thanks.


jfk EO-11110(Posted 2004) [#2]
why should this take too long? simply wrap the Animate Command and use a custom function to store the Speed parameter. So you can use the Editors Replace tool and replace Animate by My_Animate or something, then create a function My_Animate:

function My_Animate(mesh,speed,mode)
; store the speed etc.
; then start the animation as usual
end function


fall_x(Posted 2004) [#3]
Thanks for the reply.

I wrote this quick-and-dirty solution, maybe anyone is interested...

When you call AnimStart or AnimStop, an instance of type Anim is searched for the entity, if it is not found it is created... The instance stores the speed and the mode.

Use PauseAnims to pause all animations that were started with AnimStart, and use ResumeAnims to resume them.

Ta da :


Type Anim
Field entity
Field speed#
Field mode%
End Type

Function AnimStart(entity,mode%,speed#)
an.Anim=Null
For a.Anim=Each Anim
If a\entity=entity Then
an=a
Exit
End If
Next
If an=Null Then
an.Anim=New Anim
an\entity=entity
End If
an\speed=speed
an\mode=mode
Animate entity,mode,speed
End Function

Function AnimStop(entity)
an.Anim=Null
For a.Anim=Each Anim
If a\entity=entity Then
an=a
Exit
End If
Next
If an=Null Then
an.Anim=New Anim
an\entity=entity
End If
an\mode=0
an\speed=0
Animate entity,0
End Function

Function PauseAnims()
For a.Anim=Each Anim
SetAnimTime a\entity,AnimTime(a\entity)
Next
End Function

Function ResumeAnims()
For a.Anim=Each Anim
If a\mode=0 Then
Animate a\entity,0
Else
Animate a\entity,a\mode,a\speed
End If
Next
End Function


fall_x(Posted 2004) [#4]
ok, actually, this doesn't work, because when I restart the paused animation with animate, it is restarted... so I can easily pause an animation with setanimtime, I have no idea how to resume it.
any suggestions?


GfK(Posted 2004) [#5]
Use 'UpdateWorld(0)' if you don't want to update animation.


fall_x(Posted 2004) [#6]
Thank you!