diff --git a/direct/src/interval/Interval.py b/direct/src/interval/Interval.py index 961137eff6..925298062b 100644 --- a/direct/src/interval/Interval.py +++ b/direct/src/interval/Interval.py @@ -170,6 +170,24 @@ class Interval(DirectObject): def isPlaying(self): return taskMgr.hasTaskNamed(self.getName() + '-play') + def getPlayRate(self): + """ Returns the play rate as set by the last call to start(), + loop(), or setPlayRate(). """ + return self.__playRate + + def setPlayRate(self, playRate): + """ Changes the play rate of the interval. If the interval is + already started, this changes its speed on-the-fly. Note that + since playRate is a parameter to start() and loop(), the next + call to start() or loop() will reset this parameter. """ + + if self.isPlaying(): + self.pause() + self.__playRate = playRate + self.resume() + else: + self.__playRate = playRate + def setDoneEvent(self, event): self.doneEvent = event diff --git a/direct/src/interval/cInterval.cxx b/direct/src/interval/cInterval.cxx index 2faad02504..6bfda43e45 100644 --- a/direct/src/interval/cInterval.cxx +++ b/direct/src/interval/cInterval.cxx @@ -288,6 +288,37 @@ is_playing() const { return (index >= 0); } +//////////////////////////////////////////////////////////////////// +// Function: CInterval::get_play_rate +// Access: Published +// Description: Returns the play rate as set by the last call to +// start(), loop(), or set_play_rate(). +//////////////////////////////////////////////////////////////////// +double CInterval:: +get_play_rate() const { + return _play_rate; +} + +//////////////////////////////////////////////////////////////////// +// Function: CInterval::set_play_rate +// Access: Published +// Description: Changes the play rate of the interval. If the +// interval is already started, this changes its speed +// on-the-fly. Note that since play_rate is a parameter +// to start() and loop(), the next call to start() or +// loop() will reset this parameter. +//////////////////////////////////////////////////////////////////// +void CInterval:: +set_play_rate(double play_rate) { + if (is_playing()) { + pause(); + _play_rate = play_rate; + resume(); + } else { + _play_rate = play_rate; + } +} + //////////////////////////////////////////////////////////////////// // Function: CInterval::priv_do_event // Access: Published diff --git a/direct/src/interval/cInterval.h b/direct/src/interval/cInterval.h index 1d3b0414cb..083161e7fe 100644 --- a/direct/src/interval/cInterval.h +++ b/direct/src/interval/cInterval.h @@ -98,6 +98,9 @@ PUBLISHED: void clear_to_initial(); bool is_playing() const; + double get_play_rate() const; + void set_play_rate(double play_rate); + // These functions control the actual playback of the interval. // Don't call them directly; they're intended to be called from a // supervising object, e.g. the Python start() .. finish()