public void setTileGID(int gid, CCPoint pos) { int num = this.tileGIDAt(pos); if (num != gid) { if (gid == 0) { this.removeTileAt(pos); return; } if (num == 0) { this.insertTileForGID(gid, pos); return; } int num1 = (int)(pos.x + pos.y * this.m_tLayerSize.width); CCSprite childByTag = (CCSprite)base.getChildByTag(num1); if (childByTag != null) { CCRect cCRect = this.m_pTileSet.rectForGID(gid); cCRect = new CCRect(cCRect.origin.x / this.m_fContentScaleFactor, cCRect.origin.y / this.m_fContentScaleFactor, cCRect.size.width / this.m_fContentScaleFactor, cCRect.size.height / this.m_fContentScaleFactor); childByTag.setTextureRectInPixels(cCRect, false, cCRect.size); this.m_pTiles[num1] = gid; return; } this.updateTileForGID(gid, pos); } }
/// <summary> /// sets the tile gid (gid = tile global id) at a given tile coordinate. /// The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1. /// If a tile is already placed at that position, then it will be removed. /// </summary> public void setTileGID(int gid, CCPoint pos) { Debug.Assert(pos.x < m_tLayerSize.width && pos.y < m_tLayerSize.height && pos.x >= 0 && pos.y >= 0, "TMXLayer: invalid position"); Debug.Assert(m_pTiles != null && m_pAtlasIndexArray != null, "TMXLayer: the tiles map has been released"); Debug.Assert(gid == 0 || gid >= m_pTileSet.m_uFirstGid, "TMXLayer: invalid gid"); int currentGID = tileGIDAt(pos); if (currentGID != gid) { // setting gid=0 is equal to remove the tile if (gid == 0) { removeTileAt(pos); } // empty tile. create a new one else if (currentGID == 0) { insertTileForGID(gid, pos); } // modifying an existing tile with a non-empty tile else { int z = (int)(pos.x + pos.y * m_tLayerSize.width); CCSprite sprite = (CCSprite)getChildByTag((int)z); if (sprite != null) { CCRect rect = m_pTileSet.rectForGID(gid); rect = new CCRect(rect.origin.x / m_fContentScaleFactor, rect.origin.y / m_fContentScaleFactor, rect.size.width / m_fContentScaleFactor, rect.size.height / m_fContentScaleFactor); sprite.setTextureRectInPixels(rect, false, rect.size); m_pTiles[z] = gid; } else { updateTileForGID(gid, pos); } } } }
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; }