Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:20:23+00:00 2026-06-11T13:20:23+00:00

Okay, I’m making a little game/prototype with Pyglet, and I’m getting confused about events.

  • 0

Okay, I’m making a little game/prototype with Pyglet, and I’m getting confused about events.
The game runs poorly, and by profiling I know it’s because of on_draw() getting called 60 times per second because of pyglet.clock.schedule_interval(). I don’t exactly know why on_draw() is currently using all the CPU it can get its hands on, and that would be nice to know. By profiling some more, I know that drawing 100 Sprites takes a lot of CPU too, more than I think it should be taking (I don’t even know if it should be taking CPU or only GPU).

  1. What does on_draw() do by default and can I avoid any useless extra stuff?
  2. How can I make so that schedule_interval() doesn’t trigger on_draw()?
  3. Any effective drawing/blitting methods?

Some code:

screen = pyglet.window.Window(800, 600, vsync=False, caption="Project")

tileimage = pyglet.image.create(50, 50, pyglet.image.SolidColorImagePattern((0, 255, 0, 255)))

class tileclass(pyglet.sprite.Sprite):
    def __init__(self, x, y):
        pyglet.sprite.Sprite.__init__(self, tileimage)
        self.x = x
        self.y = y
        self.rect = pygame.Rect(self.x - self.width / 2, self.y - self.height / 2, self.width, self.height)
        self.image.anchor_x = self.width // 2
        self.image.anchor_y = self.height // 2

tiles = []

x = 25
y = 25
for i in range(100):
    tiles.append(tileclass(x, y))
    if x == 475:
        x = 25
        y+=50
    else:
        x+=50

@screen.event
def on_draw():
    screen.clear()
    for t in tiles:
        t.draw()
    fps.draw()

pyglet.clock.schedule_interval(update, 1/60) #Logic stuff

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:20:24+00:00Added an answer on June 11, 2026 at 1:20 pm

    Try and add your sprites to a batch and draw that instead. In pyglet its slow to do draw calls as thats how OpenGL works. Basically you want to minimize the number of draws you do and batch things together as much as possible. I got a massive improvement in your example by creating a batch and then adding all the sprites to it and finally only draw the batch.

    http://pyglet.org/doc/programming_guide/displaying_images.html#sprites

    This is a bit of contrast to pygame where a small image is cheaper than a large one and you usually make your game faster by drawing less pixels (typically only redraw parts of screen that has changes since last frame and so on).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, this is probably a very basic question; but, I'm just getting back in
Okay I know right off the bat this is going to be a stupid
Okay I'm trying to move from VB to C# with mixed success. I'm getting
Okay, I'm a little fuzzy on how this works or if it's possible. I
Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay, bear with me on this, I know it's going to look horribly convoluted,
Okay, so I'm making a table right now for Box Items. Now, a Box
Okay. I know this looks like the typical Why didn't he just Google it
Okay, we know that the following two lines are equivalent - (0 == i)
Okay, so I know that using eval() isn't great, but I haven't been able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.