Smooth motion in pyglet should always take place inside an event loop 
specified by an interval scheduled function. On_draw will never fire in the 
middle of that loop unless you have code in the loop that tells it to. 
Since your loop function must accept a dt parameter, you can ensure your 
motion is correctly interpolated. For example:

import pyglet
window = pyglet.window.Window(800, 800)
mypic = pyglet.resource.image('mypic.jpg')
sprite = pyglet.sprite.Sprite(mypic, x=0, y=0, subpixel=True)

def move_sprite(dt):
    sprite.x += 50*dt

@window.event
def on_draw():
    window.clear()
    sprite.draw()

pyglet.clock.schedule_interval(move_sprite, 1.0/60)

pyglet.app.run()



In this code, on_draw() will be called every time pyglet's clock has 
completed move_sprite. If the interval isn't exactly one sixtieth of a 
second it doesn't matter, the clock will pass the dt of when it actually 
firs, not when it was scehduled.


On Wednesday, October 26, 2016 at 2:19:47 PM UTC-5, Baitshop wrote:
>
> I was wondering if a fixed timestep is possible with pyglet's current 
> event loop? When using schedule_interval for 1/60.0 it's not always 
> consistent since it is using a variable time step.
>
> How is one supposed to separate the rendering from the updates considering 
> adjusting the position of the sprite will move it next time it is drawn.  I 
> am also having trouble understanding how interpolation would be configured 
> using the pyglet app system as the on_draw does not get passed any dt. I 
> have tried an older implementation that I found, but it seems like it fires 
> the scheduled function faster than the dt actually is. Would anyone happen 
> to have a proper example of how a fixed time step would work using a sprite 
> and pyglet?
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to