[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Layered Sprite Groups within Layered Sprite Groups



Am 01.08.2013 20:51, schrieb Andrew Barlow:
Hello,
I'm back with another blitting / Sprite / Layer Group Issue!
So, I've got a map which is on a grid (of course). This map has a layer group in it which is just the tiles. The tile sprites have a layer number (as per the DirtySprite documentation). This layer number is the Y axis of my grid (makes sense)! So, if my Tile sprite is just a DirtySprite type (http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.DirtySprite) and I draw my maps LayeredDirty group the map draws correctly, with the tiles layered on top of eachother as they should be. However, to add an extra layer of flexibility, I am trying to make layers inside the tiles too! I'm hoping to have 3 layers for each tile (Background, Decoraction and Unit). So, currently i'm trying to make a LayeredDirty group inside each tile object, where each layer in that tile is a DirtySprite (like the tile itself). Then, when the tile is dirty, ITS OWN LayeredDirty group is redrawn to the tiles image property, which in turn should then be drawn when the maps LayeredDirty group is drawn later. However, at the moment, when the next layer in the Y axis is drawn, I just get black squares and only the top half of the tile above (the layering is clearly not working correctly). Hopefully all that makes sense (its very hot here at the moment, hard to make any sense in this heat)! This link below is from some rough code I've thrown about to try and get this to work!
https://docs.google.com/file/d/0B40CJaTKX9a_azdhRHg4T2V0eTQ/edit?usp=sharing
Any help with this would be mega, I've been stabbing at it for about a week now!
Cheers in advance

Hi Andrew

I'm not sure if I understood it correctly what you are trying to do. You want to add extra layers to each tile?

I looked at your code and I think I got it working. It was working all right already, but what it messed it up was the surface creation (in tiles.py, line ~40, see attachment for changes). The problem here is, that pygame.Surface((w, h)) will return a surface optimal for the screen, but that is not what you use in the images (they have alpha transparency I guess). So to get a surface that has the same properties as the loaded image surface, you have to pass it the original surface (see the constructor Surface((width, height), flags=0, Surface)). I used the grass tile here as you had experimented with it already.

The other changes involve calling self.draw() in the constructors of the classes that inherit from Tile().

Hope that helps.

~DR0ID

PS: could you provide source in a public download way, I hate to have to log in to something to download it

Attachment: tiles.py
Description: application/python