I debated posting my code to google code to show this in context, but I'm not sure it's necessary.

This part of my program produces an unexpected result sometimes:

def assign_tile(self, cell, index):

        attribute, n = index
        tileset = getattr(self, attribute)

        tile = Sprite(tileset[n])
        tile.position = cell.get_position()

        if attribute == 'floors':
            level = 0
        elif attribute == 'walls':
            level = 1

        tilename = cell.__id__ + attribute

        self.clear_tile(cell, index)
        self.batch.add(tile, name=tilename, z=level)

The idea being that walls are always on top of floors when creating tiles. However, sometimes they are in reverse, the 'walls' gets in a lower level than 'floors'. It's never random or changing or anything like that within one instance of the program, but under some circumstances the order is reversed. Can this be explained by some peculiarity of BatchNode? Other than that I do not see any logical reason why the script would behave like this.

I fixed it by separating the batch nodes:

self.floor_tiles = BatchNode()
self.wall_tiles = BatchNode()

# ...

if attribute == 'floors':
    self.floor_tiles.add(tile, name=cell.__id__)

elif attribute == 'walls':
    self.wall_tiles.add(tile, name=cell.__id__)

I'm haven't tested whether this will impact performance for large maps.

Any ideas what may cause the original bug behaviour?

Any reason to prefer fewer batches to more?

--
You received this message because you are subscribed to the Google Groups "cocos2d 
discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to