[SOLVED] changing ival/sequence/parallel speed?

I wonder if it is possible to change the duration (in seconds) of the interval when it is actually running?
How about of a sequence that contains 2 such intervals?

No, not normally, though you can wrap a sequence or other interval inside an IndirectInterval, which can make parts of it play faster than others. But still, you have to set all of this up ahead of time.

Intervals are generally intended to be for static playback. If you want something that needs to change dynamically, you need to use a task.

David

Okay,
but can’t I at least set the time of the sequence (containing only intervals) somehow?

You can set it at construction time. You can’t change it while it is playing.

If you want to play the nested intervals faster than they would normally play, an IndirectInterval can do this for you.

David

No, I don’t mean the speed now, I mean the time, that is, the position of the sequence.
Like if my sequence has 2 intervals ,each lasting 4 seconds, I would do something like sequence.setT(6) and it would start running from the half of the 2nd interval.

I would really want something like this or I will have to port some code I wrote earlier…

Yes, you can do exactly this, sequence.setT(6). Have you tried it?

The only caveat is, it will always do any actions between the current time and the time you set it to, so if you have any Func() intervals that are supposed to fire at time 3, for instance, they will fire when you skip over time 3. This is because an Interval represents a particular set of the world at each point along the timeline, so when you skip to a particular time, it means to set the world to that state.

David

Oh, the problem was I did

seq = Sequence(ival1,ival2).loop()
seq.setT(6)

and I got an error,
but when I did

seq = Sequence(ival1,ival2)
seq.loop()
seq.setT(6)

then I didn’t get an error

Shouldn’t this kinda work?

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *


base.cam.setPos(0,-8,0)

smiley = loader.loadModel("smiley")
smiley.reparentTo(render)

x = 1 # speed

smileyIval = LerpColorScaleInterval(smiley, x, Vec4(0,1,0,1), Vec4(0,0,0,1))
smileyIval.loop()

def setIvalSpeed():
	global x
	
	oldPos = smileyIval.getT()
	print oldPos
	smileyIval.finish()
	x = slider['value']
	smileyIval.setT(oldPos*x)
	smileyIval.loop()
	print x

slider = DirectSlider(range = (1,20), value=1, pageSize = 1, command = setIvalSpeed)
slider.setPos(0,0,0.6)

run()

Well, you’re just skipping around in the interval, not changing the speed. If you actually want to change the playback speed, you have to call setT() each frame, in a task. Of course, now you’re back to writing a task, which was what I suggested in the first place. :slight_smile:

David

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *


base.cam.setPos(0,-8,0)

smiley = loader.loadModel("smiley")
smiley.reparentTo(render)

x = 1 # speed

smileyIval = LerpColorScaleInterval(smiley, x, Vec4(0,1,0,1), Vec4(0,0,0,1))
smileyIval.loop()

def setIvalSpeed():
   global x

   if x==slider['value']: return
   x = slider['value']
   smileyIval.setPlayRate(x)
   print x

slider = DirectSlider(range = (1,20), value=1, pageSize = 1, command = setIvalSpeed)
slider.setPos(0,0,0.6)

run()

Doh! I completely forgot about Interval.setPlayRate(). Oops. :slight_smile:

David

Well I don’t want you to think I ignored what you said before and made you repeat yourself.

It’s just that this got me a bit confused. I thought you ment ‘ahead of time’ as ‘before calling .start() or .loop() on the interval’, so I thought I could finish() the interval, change the speed variable, calculate the new position and call .loop() again. But I guess you ment ‘when referencing the interval’ as ‘ahead of time’, huh?

EDIT: ^ will do :slight_smile:

No, I really had meant ‘before you call start()’. Simply calling setT() while it is playing doesn’t change the interval’s speed, unless you call it every frame.

These are the ways to change an interval’s speed:
(1) call setPlayRate() (which I’d forgotten about).
(2) wrap it inside an IndirectInterval at construction time.
(3) call setT() every frame in a task.
(4) rewrite the interval completely using the task system instead of the interval system.

David

This is solved, but

I kinow that.
But is that all I do here?:

def setIvalSpeed():
   global x
   
   oldPos = smileyIval.getT()
   print oldPos
   smileyIval.finish()
   x = slider['value']
   smileyIval.setT(oldPos*x)
   smileyIval.loop()
   print x 

Don’t I kinda finish the interval and also change the speed variable here?

oh wait drwr! i abstracted a other way which would work :smiley:

you could also scale the world :smiley: :smiley: :smiley:

intervals are pretty nice, but in the most cases they arnt very handsome. often its better to write your own function. specially if you are playing around with very dynamical things.

krid… if I didn’t know better I would say youre a spammer :question:

lol, i just gave you a other option :smiley: ok, this would be a very strange way. :smiley: but in a abstract way it would also work. dont use this way, its just a abstract idea.

why to change the time, if you can fold the space? :smiley: