There are many examples of how to correctly use Rabbyt sprites in the
Rabbyt source code, under the 'examples' directory. View them online here:
https://bitbucket.org/mmarshall/rabbyt/src/tip/examples/
Cheers,
Jonathan
--
Jonathan Hartley tar...@tartley.com http://tartley.com
Made of meat. +44 7737 062 225 twitter/skype: tartley
MWM
> --
> You received this message because you are subscribed to the Google Groups "Rabbyt" group.
> To post to this group, send email to rab...@googlegroups.com.
> To unsubscribe from this group, send email to rabbyt+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rabbyt?hl=en.
>
>
Something like this:
def update(self, dt):
self.frame += dt*animation_frames_per_second
self.tex_shape = self.animation_frames[int(self.frame) %
len(self.animation_frames)]
MWM
An alternative, possibly simpler, way to think about it if you instead
would prefer smooth animation from one position to the next, is as follows:
In order for the object to move slower, you have to increment its
position by less each frame. Instead of doing "shape.left +=
shape.width" each frame, how about adding a new, smaller value to it,
which I'll call 'SPEED':
SPEED = 1.0
def update(self, dt):
self.tex_shape.left += SPEED
Now 'SPEED' can be defined as a module level constant, as I've done
here, or it can be put as a property on your sprite, which might be
better if you end up having several moving things and a different speed
for each of them.
There is a problem with this, which is that if you are on a fast
computer, your frames will be drawn rapidly, and the sprite will move
faster than if you are on a slow computer (or if your computer is busy
with another CPU hogging program). The way to compensate for this is to
multiply the speed by the value of 'dt' passed to update:
def update(self, dt):
self.tex_shape.left += SPEED * dt
As you seem to have already noticed, the very first time pyglet calls
'update', the value of dt is zero, so you need to guard against that. I
use 'max':
def update(self, dt):
dt = max(dt, 1/60.0)
self.tex_shape.left += SPEED * dt
Also, if for some reason your computer gets really slow (or maybe if
someone hits the 'pause' key) then the value of dt will get really
large, perhaps so large that it breaks the program in some way (e.g.
imagine adding a value to shape.left that moved the object miles off the
screen) So you also need to guard against that. I use 'min':
def update(self, dt):
dt = min(1/30.0, max(dt, 1/60.0))
self.tex_shape.left += SPEED * dt
Now you've got this in place, you can tweak the value of speed to achive
the effect you want.
This should work, more or less. There are some issues:
Firstly, you need to remember that if you are changing any other
gameplay-related values over time, then generally speaking you ought to
remember to scale the rate of change by 'dt' for those values too. (e.g.
if you were gradually turning up the lights to make your sprite visible,
and you wanted the lights to reach full brightness just as the sprite
reached the center of the screen, then you need to remember to scale the
light-brightening by dt too, or else of a slow computer the two will get
the spite movement and light brightening out of sync)
I once posted an overly-long post about the implications of this, such
as how to scale things that you are multiplying instead of adding, here:
http://www.mail-archive.com/pyglet...@googlegroups.com/msg05080.html
Secondly, this doesn't deal well if dt ends up changing rapidly from one
frame to the next. This might happen if you get the odd slow frame, due
to your game occasionally doing some sporadic processing, or if your
computer gets distracted dealing with some other process. This will
manifest as a flicker of jerky-looking motion. I think you might be
able to improve this somewhat by using a rolling-average value for dt,
but I've never actually tried this out myself.
Cheers,
Jonathan