On Thu, Oct 31, 2013 at 6:44 PM, John Ladasky <[email protected]>wrote:

> Hi folks,
>
> I'm continuing to work with Pyglet, and I'm getting results, but also
> problems.  Here is a simple application which I developed first on my
> Ubuntu Linux 13.04 system, 64-bit version, AMD CPU, running Python 3.3.2
> and pyglet 1.2alpha1.  This is a "hello world" program, with Earth as a
> bouncing ball in the background.
>
> ===================================================================
>
> import pyglet
> from random import uniform, choice
>
> def random_velocity():
>     return [choice((-1,1)) * uniform(0.25,0.75) for x in range(2)]
>
> class MyWindow(pyglet.window.Window):
>
>     def __init__(self, *args, **kwargs):
>         super().__init__(*args, **kwargs)
>         self.label = pyglet.text.Label(
>             'Hello, crazy world!',
>             font_name='Times New Roman',
>             font_size=40,
>             x = self.width//2, y = self.height//3,
>             anchor_x='center', anchor_y='center')
>         img = pyglet.resource.image('Earth 99x99.png')
>         self.sprite = pyglet.sprite.Sprite(
>             img,
>             x = (self.width - img.width)//2,
>             y = 2*self.height//3 - img.height//2)
>         self.sprite.vx, self.sprite.vy = random_velocity()
>         # Bounce boundaries
>         self.left = 5
>         self.right = self.width - img.width - 5
>         self.bottom = 5
>         self.top = self.height - img.height - 5
>         # Animation clock
>         pyglet.clock.schedule_interval(self.update, 1 / 60.0)
>
>     def on_draw(self):
>         self.clear()
>         self.sprite.draw()
>         self.label.draw()
>
>     def update(self, dt):
>         sp = self.sprite
>         sp.x += sp.vx
>         sp.y += sp.vy
>         if sp.x < self.left or sp.x > self.right:
>             sp.vx = -sp.vx
>         if sp.y < self.bottom or sp.y > self.top:
>             sp.vy = -sp.vy
>         sp.draw()
>
> MyWindow()
> pyglet.app.run()
>
>
> ===================================================================
>
>

Your update method should not call sp.draw(); You always draw in the .draw
method.

For smooth movement the position update should use the received dt, like
sp.x += sp.vx * dt

Other than that,  I don't see anything strange.

What happens if you run pyglet's included sample examples/noisy/noisy.py ?

-- 
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 http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to