On Thu, 2008-09-11 at 11:28 +1000, Richard Jones wrote:
> Hi there, I have need of a MoveTo action that takes the speed to move at,
> rather than the duration to move by.
>
> Can anyone help please?
uh, I didn't commit this, but I have the code...
in base_actions.py, class IntervalAction
+ @staticmethod
+ def duration_or_speed (p1, p2, duration=None, speed=None):
+ """Computes the duration of an action that goes from `p1` to
+ `p2`. Action must have a given `speed` (in distance units
+ per second), or a given 'duration', but not both.
+ """
+ if speed is None:
+ if duration is None:
+ raise TypeError ('You must specify either duration or
speed')
+ # duration is not None
+ return duration
+ # speed is not None
+ if duration is not None:
+ raise TypeError ('You can not specify both duration and
speed')
+ x1, y1 = p1
+ x2, y2 = p2
+ return ((x2-x1)**2 + (y2-y1)**2)**0.5 / speed
+
in cocos/actions/interval_actions.py, class MoveBy:
- def init(self, delta, duration=5):
+ def init(self, delta, duration=None, speed=None):
...
- self.duration = duration
+ self.duration = self.duration_or_speed((0, 0), delta, duration,
speed)
With that, you can do:
MoveBy(200,0, duration=20)
or
MoveBy(200,0, speed=10)
Regards,
D.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---