slycrel / JSTileMap

TMX Map viewer for SpriteKit
Other
212 stars 34 forks source link

Scrolling glitch like issue #14 #23

Closed sushi1986 closed 9 years ago

sushi1986 commented 10 years ago

Hi there,

I am using your tile map implementation and there are little problems. If I try to move the map with "position.x += 0.1", there will be little glitches when Sprite Kit loads new sprites. Every time a column or row of tiles disappears and a new one should appear there are little black lines between the tiles. I could observe this behavior on different iPhones with different maps (Including your examples).

After reading issue #14 and JRams post

"I did some extensive performance testing and Spritekit's native batch rendering is much much faster than using a tilemap. I tested the exact same maps and assets on both (using tilemap vs using raw png's and adding actions to those).

This doesn't really make much sense to me since I thought breaking big images into tiles should result in better performance. I guess Spritekit does a better job optimizing and batch rendering than I thought."

I tried to include a SKTextureMap and this solves my problem. There were no glitches anymore. I replaced the function "textureForGid:(int)gid" with: " -(SKTexture*)textureForGid:(int)gid {

gid = gid & kFlippedMask;
gid -= self.firstGid;

SKTexture* texture = self.textureCache[@(gid)];
if(!texture)
{
    int col =[self colFromGid:gid];
    int row =[self rowFromGid:gid];

    NSString* s  = [NSString stringWithFormat:@"tiles%0.3d",(int)(col + row * self.atlasTexture.size.width/ self.tileSize.width)];
    NSLog(@"Number: %@",s);
    texture = [_textureAtlas textureNamed:s];
self.textureCache[@(gid)] = texture;

}
return texture;

} "

But I don't know exactly where to init the texture atlases. I thought I should do it in "-(void)setSourceImage:(NSString *)sourceImage" but there sourceImage contains the full path to the image.

Can you help me to find a good position for initializing the needed SKTextureAtlas? Perhaps you could provide an alternative implementation of your map here on github.

Thanks,

sushi1986

slycrel commented 9 years ago

Hi @sushi1986,

If you were to change JSTileMap to use SKTextureAtlas instead of SKTexture then you would want to replace the TMXTilesetInfo atlasTexture with your SKTextureAtlas. This is loaded in the setSourceImage: method.

slycrel commented 9 years ago

@sushi1986 I hope you got this taken care of. Feel free to leave a comment here about your resolution. If you have any additional questions please create a new issue.