0

I am getting some weird distortion of my CCLabelBMFont labels in Cocos2D, as noted here:

example example

The distortions appear on both iPad device and simulator. Notable points about this:

  • I have other labels using the same font file that are not showing this
  • I have made sure the coordinates of the labels are all integers, no floats
  • there is no scaling of the labels
  • I have tried with and without [label.texture setAliasTexParameters]; no difference
  • If I move the label to a different coordinate, it sometimes corrects the distortion

Any idea what could be going on?

UPDATE: I changed my label to a TTF label, and the issue remains! Even when no font file is used, the distortion is appearing.

johnbakers
  • 24,158
  • 24
  • 130
  • 258

2 Answers2

2

Some digging on Cocos2d forums led me to add this:

[[CCDirector sharedDirector] setProjection:CCDirectorProjection2D];

Seems to resolve the issue. Anyone know if this has other undesired side-effects, since this is not the default projection in Cocos2d.

UPDATE This solved my issue on iOS 4 only but my issue persists on iOS 5. I am now seeing that the distortion can be removed by adjusting the anchor point of the label, so it seems to be affected by that. Probably a bug?

UPDATE 2 It turns out that my symptoms were caused by two different things. The projection did in fact make a difference with some sorts of distortion and on all iOS versions, so this above code is useful. But second, I found a conditional statement that sets the position of the font label and it was not always creating integer coordinates. So, by placing (int) in front of the x and y parts of the coordinate, the issue resolved. Sprites can handle floating point coordinates without distortion, but CClabels cannot, it seems.

johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • In fact, I'm having trouble finding any documentation on the reasons for using different projection types. Any help is appreciated. – johnbakers Jun 14 '12 at 07:47
  • Good question, I've been wondering that myself. New question (with my use cases): http://stackoverflow.com/questions/11030664/what-is-the-difference-between-2d-and-3d-projection-in-cocos2d-iphone – CodeSmile Jun 14 '12 at 09:55
1

Add some spacing around each character. This is normally caused by other nearby glyphs from the texture atlas "bleeding" into one another due to texture filtering. Both Glyph Designer and Hiero allow you to specify spacing, typically a value of two pixels between each glyph is enough to stop bleeding.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • It turns out my solution to change the projection type only resolved the issue on iOS 4, but it remained on iOS 5 so I tried your suggesting and increased by spacing and padding, but my issue remains, unfortunately. What's weird is that it does not affect all labels using that font, even though all labels are setup exactly the same. – johnbakers Jun 14 '12 at 13:01
  • I have further confirmed that the issue is identical even if I use a TTF label and no font file, so it is not due to spacing after all – johnbakers Jun 15 '12 at 03:47