Reputation: 3350
Here is my cocos code:
class Startbox(Layer):
def __init__(self):
Layer.__init__(self)
self.batch = BatchNode()
self.add(self.batch)
img = pyglet.image.load('images/map_sprites.png')
tileset = pyglet.image.ImageGrid(img, 3, 15, 96, 96)
x, y = 0, 0
for i in range(10):
for j in range(10):
spr = Sprite(tileset[1])
spr.x = x
spr.y = y
self.batch.add(spr)
x += 96
y += 96
x = 0
I'm trying to get a sprite and display is side by side to cover the window. That code produces a faulty result, the tiles have a space between them like this:
I don't understand why this happens, or how to fix it. The following pyglet code does basically the same thing, but with the sprites properly lined up and not creating any black lines:
class screen(pyglet.window.Window):
def __init__(self, w, h):
super(screen, self).__init__(w, h)
sprite_sheet = grid(pyglet.image.load("images/map_sprites.png"), 3, 15)
self.batch = pyglet.graphics.Batch()
self.all_sprites = []
x, y = 0, 0
for i in range(10):
for j in range(10):
sprite = pyglet.sprite.Sprite(sprite_sheet[1], batch=self.batch)
sprite.x = x
sprite.y = y
self.all_sprites.append(sprite)
x += 96
y += 96
x = 0
EDIT: I found the solution, and wanted to post it as an answer for the sake of clarity in case someone stumbles upon this in the future, but I guess editing my OP will be sufficient.
From Claudio Canepa in the Cocos2d Google groups list:
You can try passing do_not_scale=True in the director.init call , this will use ortographic projection which is better suited for tiles.
You can look at examples for cocos tilemaps in the scripts
test_tiles.py
test_tmx.py
test_platformer.py
The implementation is ultra simple:
if __name__ == '__main__':
director.init(width, height, do_not_scale=True)
director.run(Scene(Startbox()))
Upvotes: 2
Views: 985
Reputation: 22042
Not worked in python version of cocos2d, but observed same in iPhone version of cocos2d. So this may help :-
« If SpriteSheet created with Zwoptex then add sprite spacing gap to 2px +.
« Edit ccConfig.h file and define this
#ifndef CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 1
#endif
Refer my answer in this: Thread in Stackoverflow
Upvotes: 1