public void createFontChars() { int item = 0; int mUCommonHeight = 0; int num = -1; int num1 = 0; CCSize cCSize = new CCSize(0f, 0f); int num2 = 0; int mUCommonHeight1 = 0; int num3 = 1; int length = this.m_sString.Length; if (length == 0) { return; } for (int i = 0; i < length - 1; i++) { if (this.m_sString[i] == 10) { num3++; } } mUCommonHeight1 = this.m_pConfiguration.m_uCommonHeight * num3; mUCommonHeight = -(this.m_pConfiguration.m_uCommonHeight - this.m_pConfiguration.m_uCommonHeight * num3); for (int j = 0; j < length; j++) { int mSString = this.m_sString[j]; if ((long)mSString >= (long)2048) { object[] objArray = new object[] { "LabelBMFont: character ", this.m_sString[j], " outside of max font characters, which is ", (uint)2048 }; throw new ArgumentException(string.Concat(objArray)); } if (mSString != 10) { num1 = this.kerningAmountForFirst(num, mSString); if (!this.m_pConfiguration.m_pBitmapFontArray.ContainsKey(mSString)) { throw new ArgumentException(string.Concat("Character ", mSString, " in LabelBMFont is not in the font definition.")); } ccBMFontDef _ccBMFontDef = this.m_pConfiguration.m_pBitmapFontArray[mSString]; CCRect cCRect = _ccBMFontDef.rect; CCSprite childByTag = (CCSprite)base.getChildByTag(j); if (childByTag != null) { childByTag.setTextureRectInPixels(cCRect, false, cCRect.size); childByTag.visible = true; childByTag.Opacity = 255; } else { childByTag = new CCSprite(); childByTag.initWithBatchNodeRectInPixels(this, cCRect); this.addChild(childByTag, 0, j); } float single = (float)(this.m_pConfiguration.m_uCommonHeight - _ccBMFontDef.yOffset); childByTag.positionInPixels = new CCPoint((float)(item + _ccBMFontDef.xOffset) + _ccBMFontDef.rect.size.width / 2f + (float)num1, (float)mUCommonHeight + single - cCRect.size.height / 2f); item = item + this.m_pConfiguration.m_pBitmapFontArray[mSString].xAdvance + num1; num = mSString; childByTag.IsOpacityModifyRGB = this.m_bIsOpacityModifyRGB; childByTag.Color = this.m_tColor; if (this.m_cOpacity != 255) { childByTag.Opacity = this.m_cOpacity; } if (num2 < item) { num2 = item; } } else { item = 0; mUCommonHeight = mUCommonHeight - this.m_pConfiguration.m_uCommonHeight; } } cCSize.width = (float)num2; cCSize.height = (float)mUCommonHeight1; base.contentSizeInPixels = cCSize; }
/// <summary> /// updates the font chars based on the string to render /// </summary> public void createFontChars() { int nextFontPositionX = 0; int nextFontPositionY = 0; int prev = -1; int kerningAmount = 0; CCSize tmpSize = new CCSize(0, 0); int longestLine = 0; int totalHeight = 0; int quantityOfLines = 1; int stringLen = m_sString.Length; if (0 == stringLen) { return; } for (int i = 0; i < stringLen - 1; ++i) { ushort c = m_sString[i]; if (c == '\n') { quantityOfLines++; } } totalHeight = m_pConfiguration.m_uCommonHeight * quantityOfLines; nextFontPositionY = -(m_pConfiguration.m_uCommonHeight - m_pConfiguration.m_uCommonHeight * quantityOfLines); for (int i = 0; i < stringLen; i++) { int c = m_sString[i]; if (c >= kCCBMFontMaxChars) { throw (new ArgumentException("LabelBMFont: character " + m_sString[i] + " outside of max font characters, which is " + kCCBMFontMaxChars)); } if (c == '\n') { nextFontPositionX = 0; nextFontPositionY -= (int)m_pConfiguration.m_uCommonHeight; continue; } kerningAmount = this.kerningAmountForFirst(prev, c); if (!m_pConfiguration.m_pBitmapFontArray.ContainsKey(c)) { throw(new ArgumentException("Character " + c + " in LabelBMFont is not in the font definition.")); } ccBMFontDef fontDef = m_pConfiguration.m_pBitmapFontArray[c]; CCRect rect = fontDef.rect; CCSprite fontChar = (CCSprite)(this.getChildByTag(i)); if (fontChar == null) { fontChar = new CCSprite(); fontChar.initWithBatchNodeRectInPixels(this, rect); this.addChild(fontChar, 0, i); } else { // reusing fonts //fontChar = new CCSprite(); fontChar.setTextureRectInPixels(rect, false, rect.size); // restore to default in case they were modified fontChar.visible = true; fontChar.Opacity = 255; } float yOffset = (float)(m_pConfiguration.m_uCommonHeight - fontDef.yOffset); fontChar.positionInPixels = (new CCPoint(nextFontPositionX + fontDef.xOffset + fontDef.rect.size.width / 2.0f + kerningAmount, (float)nextFontPositionY + yOffset - rect.size.height / 2.0f)); // NSLog(@"position.y: %f", fontChar.position.y); // update kerning nextFontPositionX += m_pConfiguration.m_pBitmapFontArray[c].xAdvance + kerningAmount; prev = c; // Apply label properties fontChar.IsOpacityModifyRGB = m_bIsOpacityModifyRGB; // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on fontChar.Color = m_tColor; // only apply opaccity if it is different than 255 ) // to prevent modifying the color too (issue #610) if (m_cOpacity != 255) { fontChar.Opacity = m_cOpacity; } if (longestLine < nextFontPositionX) { longestLine = nextFontPositionX; } } tmpSize.width = (float)longestLine; tmpSize.height = (float)totalHeight; this.contentSizeInPixels = tmpSize; }
/// <summary> /// updates the font chars based on the string to render /// </summary> public void createFontChars() { int nextFontPositionX = 0; int nextFontPositionY = 0; int prev = -1; int kerningAmount = 0; CCSize tmpSize = new CCSize(0, 0); int longestLine = 0; int totalHeight = 0; int quantityOfLines = 1; int stringLen = m_sString.Length; if (0 == stringLen) { return; } for (int i = 0; i < stringLen - 1; ++i) { ushort c = m_sString[i]; if (c == '\n') { quantityOfLines++; } } totalHeight = m_pConfiguration.m_uCommonHeight * quantityOfLines; nextFontPositionY = -(m_pConfiguration.m_uCommonHeight - m_pConfiguration.m_uCommonHeight * quantityOfLines); for (int i = 0; i < stringLen; i++) { int c = m_sString[i]; if (c >= kCCBMFontMaxChars) { throw (new ArgumentException("LabelBMFont: character " + m_sString[i] + " outside of max font characters, which is " + kCCBMFontMaxChars)); } if (c == '\n') { nextFontPositionX = 0; nextFontPositionY -= (int)m_pConfiguration.m_uCommonHeight; continue; } kerningAmount = this.kerningAmountForFirst(prev, c); if (!m_pConfiguration.m_pBitmapFontArray.ContainsKey(c)) { throw(new ArgumentException("Character " + c + " in LabelBMFont is not in the font definition.")); } ccBMFontDef fontDef = m_pConfiguration.m_pBitmapFontArray[c]; CCRect rect = fontDef.rect; CCSprite fontChar = (CCSprite)(this.getChildByTag(i)); if (fontChar == null) { fontChar = new CCSprite(); fontChar.initWithBatchNodeRectInPixels(this, rect); this.addChild(fontChar, 0, i); } else { // reusing fonts //fontChar = new CCSprite(); fontChar.setTextureRectInPixels(rect, false, rect.size); // restore to default in case they were modified fontChar.visible = true; fontChar.Opacity = 255; } float yOffset = (float)(m_pConfiguration.m_uCommonHeight - fontDef.yOffset); fontChar.positionInPixels = (new CCPoint(nextFontPositionX + fontDef.xOffset + fontDef.rect.size.width / 2.0f + kerningAmount, (float)nextFontPositionY + yOffset - rect.size.height / 2.0f)); // NSLog(@"position.y: %f", fontChar.position.y); // update kerning nextFontPositionX += m_pConfiguration.m_pBitmapFontArray[c].xAdvance + kerningAmount; prev = c; // Apply label properties fontChar.IsOpacityModifyRGB = m_bIsOpacityModifyRGB; // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on fontChar.Color = m_tColor; // only apply opaccity if it is different than 255 ) // to prevent modifying the color too (issue #610) if (m_cOpacity != 255) { fontChar.Opacity = m_cOpacity; } if (longestLine < nextFontPositionX) { longestLine = nextFontPositionX; } } tmpSize.width = (float)longestLine; tmpSize.height = (float)totalHeight; this.contentSizeInPixels = tmpSize; }