Thursday, April 26, 2012

Pyglet and tiles

This is my second attempt to move the graphics to the hardware-acceleration friendly pyglet module.  The thing that held me up the first time is a thing that I'm currently making headway on right now: writing a tile engine for it.

pyglet comes with built-in support for sprites, and in fact to get good use out of it it's important to use its sprite class instead of pushing images to the screen yourself, which I had been doing with Pygame.  pyglet's sprite rendering loop takes care of queueing its "official" sprites and sending them to OpenGL, and the video card, for you, so as long as you use its sprite class to display images.  The word is this is worth a substantial boost when drawing.

But pyglet doesn't provide as simple a mechanism for drawing tiles, meaning I have to simulate them with a field of sprites.  I'm doing this with an array of sprites that more-or-less mirrors those onscreen.  As the map scrolls around and new tiles enter the screen, the sprites that scrolled off are moved to the other side of the screen and updated to reflect the new map section.

Or at least that's the plan.  The problem is keeping the coordinate translations between the screen, the sprite frame, and the map all straight in my head, which has always been kind of a problem for me, probably due to some dyslexia.  Still, it seems to be coming along well for now.

No comments:

Post a Comment