(I am not english. Hope you understand.)
Hi, I'm trying to move my "start_button" sprite to x = 150, but it'll duplicate it. Here's the code:
import pyglet
window = pyglet.window.Window()
window.clear()
#ON_TEXT
def ontext(txt):
start_button.x = 150
#INTERVAL
def interval(int):
print("Running")
pyglet.clock.schedule_interval(interval, 1/30)
#SPRITES
def paint():
start_button.draw()
start_button_pic = pyglet.image.load("start_button.png")
start_button = pyglet.sprite.Sprite(start_button_pic)
#PUSH_HANDLERS
window.push_handlers(
on_text=ontext,
on_draw=paint,
)
pyglet.app.run()
print("Done")
Thanks for answers!
Andrew
You need to clear the window, before drawing the sprite:
def paint():
window.clear()
start_button.draw()
The clear
method clears the color and depth buffer (see pyglet.window
). Actually, the sprite is not duplicated, but the sprite drawn in the previous frames is still there because the color buffer was never cleared.