august7cbfa7b7
august7cbfa7b7

Reputation: 1244

Why does gaps between tiles in an orthogonal tilemap cocos2d game appear when running on iPhone?

I'm trying to make a tilemap-based game using cocos2d 2.1 and Tiled 0.9.1. The game runs perfectly on the simulator, but I have gaps (artifact lines) between the tiles when running on the device.

Please see the screenshot.

Gaps between tilemap

The diff is the difference (made in photoshop) between the original tile (taken straight from the png of the tileset) and the tile as rendered by cocos2d. As you can see, in simulator they are 100% identical. However, on the device it seems that cocos2d shrinks the tile texture vertically by just a little bit. The 1 pixel stripe is actually the texture above the troublesome tile in the tileset.

Any idea what caused this and how to fix it?

Upvotes: 0

Views: 973

Answers (2)

Dmitry
Dmitry

Reputation: 417

While using this answer In my case enabling CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL was not enough.

I also added the following code to AppDelegate::applicationDidFinishLaunching() function and rounded values passed to setPosition(x, y) function to nearest int.

Director::getInstance()->setProjection(Director::Projection::_2D);

I use cocos2d-x 3.4.

Upvotes: 2

YvesLeBorg
YvesLeBorg

Reputation: 9079

Not certain why this happens on devices only, but you should read in ccConfig.h for parameter CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL. This in itself is a bad kludge, but it gives you a hint as to where to look.

Basically, you should make certain that all your positions are on an exact pixel boundary, ie on non-retina devices cast them to int, and on retina devices round to the nearest exact multiple of .5. Best way to ensure that is to make all your textures w,h even numbers ... the onus is on the artist for anything that will not move. If you move things, and the final position is calculated (for example in a ccTouches move,end), make certain you do this rounding there. Beware of batch nodes : the node itself, and all its children should be on pel boundary.

Upvotes: 0

Related Questions