user1237200
user1237200

Reputation: 149

Pyglet drawing a set of images to a larger one

Is there any way to draw a whole lot of small images to a larger one so only the large image need be moved? Specifically I am making a top down tile based rpg and I was experimenting with map scrolling. Moving each tile was far slower than moving one big image so I was looking for a way to draw all the tiles onto one image (I had a look at textures but couldn't find any examples or tutorials) Is this the best way and is it possible?

Upvotes: 5

Views: 1967

Answers (1)

Josiah
Josiah

Reputation: 3326

You should check out AbstractImage.blit_into() (and derivatives of such). Here's an example that does basically what you want, where img1.png and img2.png are just copies of pyglet.png found in the examples folder of the pyglet source:

import pyglet

window = pyglet.window.Window()
image = pyglet.image.Texture.create(256,128)
img1 = pyglet.image.load('img1.png')
img2 = pyglet.image.load('img2.png')
image.blit_into(img1,0,0,0)
image.blit_into(img2,128,0,0)
@window.event
def on_draw():
    window.clear()
    image.blit(0,0)

pyglet.app.run()

Upvotes: 7

Related Questions