On Wed, Apr 23, 2008 at 2:10 PM, Carlos <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> I hope you'll bear with my low-level programming skills. First, I've
> been trying to make an image bounce. Basic, I know, but I can't for
> the life of me get it to work. Whenever I run the program, I get a
> white window for a few seconds, which then disappears. I think it may
> be because I don't know how to implement the run loop via
> clock.schedule_interval. It worked perfectly when I was using the
> older run loop (i.e. while not win.has_exit ...). If anyone could
> please help me, I'd really appreciate it. Thanks!
>
>
> from random import randrange
> import pyglet
> from pyglet.gl import *
>
> win = pyglet.window.Window(caption = "Bouncing Ball", width = 640,
> height = 402)
> background = pyglet.image.load("image1.bmp")
>
> ball = pyglet.image.load("image2.jpg")
> ballCoords = [0, 0]
> ballSlope = [5, randrange(0, 10)]
>
> def main():
> # Allow transparent portions of ball to actually be transparent
> glEnable(GL_BLEND)
> glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
>
> def animate(dt):
> # Move the object ballSlope[0] to the right and up ballSlope[1]
> ballCoords[0] += ballSlope[0]
> ballCoords[1] += ballSlope[1]
>
> # If the edge of the ball hits either the right or left edge of the
> window
> if (ballCoords[0] > win.width - ball.width) or (ballCoords[0] < 0):
> ballSlope[0] = -ballSlope[0]
> # If the edge of the ball hits either the top or bottom edge of the
> window
> if (ballCoords[1] > win.height - ball.height) or (ballCoords[1] < 0):
> ballSlope[1] = -ballSlope[1]
>
> win.clear()
> background.blit(0, 0)
> ball.blit(ballCoords[0], ballCoords[1])
>
> pyglet.clock.schedule_interval(animate, 1/60.0)
>
> if __name__ == "__main__":
> main()
Looks like you've just forgotten to call pyglet.app.run().
Alex.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" 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/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---