public CCTileGidAndFlags TileGIDAndFlags(int column, int row) { CCTileGidAndFlags tileGIDAndFlags = new CCTileGidAndFlags(0, 0); if (AreValidTileCoordinates(column, row)) { int flattenedIndex = FlattenedTileIndex(column, row); tileGIDAndFlags = tileGIDAndFlagsArray[flattenedIndex]; } return(tileGIDAndFlags); }
public void RemoveTile(int column, int row) { if (AreValidTileCoordinates(column, row)) { CCTileGidAndFlags gidAndFlags = TileGIDAndFlags(column, row); if (gidAndFlags.Gid != 0) { // Remove tile from GID map SetBatchRenderedTileGID(column, row, CCTileGidAndFlags.EmptyTile); } } }
public void SetTileGID(CCTileGidAndFlags gidAndFlags, CCTileMapCoordinates tileCoords) { if (gidAndFlags.Gid == 0) { RemoveTile(tileCoords); return; } if (AreValidTileCoordinates(tileCoords) == false) { Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile coordinates row: {0} column: {1}", tileCoords.Row, tileCoords.Column)); return; } CCTileGidAndFlags currentGID = TileGIDAndFlags(tileCoords); if (currentGID == gidAndFlags) { return; } CCTileMapDrawBufferManager drawBufferManager = GetDrawBufferManagerByGid(gidAndFlags.Gid); if (drawBufferManager == null) { foreach (CCTileSetInfo tileSetInfo in mapInfo.Tilesets) { if (tileSetInfo.FirstGid <= gidAndFlags.Gid && tileSetInfo.LastGid >= gidAndFlags.Gid) { drawBufferManager = InitialiseDrawBuffer(tileSetInfo); break; } } if (drawBufferManagers == null) { Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile grid id: {0}", gidAndFlags.Gid)); return; } drawBufferManagers.Add(drawBufferManager); visibleTileRangeDirty = true; } SetBatchRenderedTileGID(tileCoords.Column, tileCoords.Row, gidAndFlags); }
CCTileSetInfo[] TilesetForLayer(CCTileLayerInfo layerInfo) { CCTileMapCoordinates size = layerInfo.LayerDimensions; List <CCTileSetInfo> tilesets = MapInfo.Tilesets; List <CCTileSetInfo> results = new List <CCTileSetInfo>(); int numOfTiles = size.Row * size.Column; if (tilesets != null) { for (int tilesetIdx = 0; tilesetIdx < tilesets.Count; tilesetIdx++) { CCTileSetInfo tileset = tilesets[tilesetIdx]; bool contains = false; short tilesetLastGid = (short)(tilesetIdx < tilesets.Count - 1 ? tilesets[tilesetIdx + 1].FirstGid - 1 : short.MaxValue); for (uint tileIdx = 0; tileIdx < numOfTiles; tileIdx++) { CCTileGidAndFlags gidAndFlags = layerInfo.TileGIDAndFlags[tileIdx]; if (gidAndFlags.Gid != 0 && gidAndFlags.Gid >= tileset.FirstGid && gidAndFlags.Gid <= tilesetLastGid) { //return tileset; results.Add(tileset); contains = true; break; } } if (contains) { continue; } } } if (results.Count > 0) { return(results.ToArray()); } else { CCLog.Log("CocosSharp: Warning: CCTileMapLayer: TileMap layer '{0}' has no tiles", layerInfo.Name); return(null); } }
public void ReplaceTileGIDQuad(short originalGid, short gidOfQuadToUse) { var indices = IndexBuffer.Data.Elements; for (int i = 0, N = IndexBufferSize; i < N; i += 6) { int tileIndex = (indices[i] / NumOfCornersPerQuad) + TileStartIndex; var gidAndFlag = TileMapLayer.TileGIDAndFlagsArray[tileIndex]; /* * So here we're updating the underlying quadvertexbuffer after each quad change * The alternative is to determine the min/max tile index and call QuadsVertexBuffer.UpdateBuffer() over that range. * The assumption is that replacing tile gid quads is primarily used for animating tiles that share a common original gid. * In particular, we would expect that animated tiles are small in number and/or sparsely spread out across the tile map * e.g. Water tiles/trees/character/light source etc. * So it's likely updating over a range would unnecessarily update a large number of unchanged quads */ if (gidAndFlag.Gid == originalGid) { var replacementQuadGid = new CCTileGidAndFlags(gidOfQuadToUse, gidAndFlag.Flags); UpdateQuad(tileIndex, ref replacementQuadGid, true); } } }
/// <summary> /// Sets the menu tile. /// </summary> /// <returns>The menu tile.</returns> /// <param name="posI">The positionI.</param> /// <param name="gid">The gid.</param> /// <param name="isPossible">If set to <c>true</c> is possible.</param> public CCSprite SetMenuTile(PositionI posI, CCTileGidAndFlags gid, bool isPossible = true) { m_menueLayer.SetTileGID(gid, new CCTileMapCoordinates(posI.CellPosition.CellX, posI.CellPosition.CellY)); var sprite = m_menueLayer.ExtractTile(new CCTileMapCoordinates(posI.CellPosition.CellX, posI.CellPosition.CellY), true); if (!isPossible) { sprite.Color = CCColor3B.DarkGray; } return sprite; }
public void SetTileGID(CCTileGidAndFlags gidAndFlags, CCTileMapCoordinates tileCoords) { if (gidAndFlags.Gid == 0 || gidAndFlags.Gid < TileSetInfo.FirstGid) { Debug.Assert (false, String.Format("CCTileMapLayer: SetTileGID: Invalid GID %n", gidAndFlags.Gid)); return; } if (AreValidTileCoordinates(tileCoords) == false) { Debug.Assert (false, String.Format("CCTileMapLayer: Invalid tile coordinates row: %n column: %n", tileCoords.Row, tileCoords.Column)); return; } CCTileGidAndFlags currentGID = TileGIDAndFlags(tileCoords); if(currentGID == gidAndFlags) return; SetBatchRenderedTileGID(tileCoords.Column, tileCoords.Row, gidAndFlags); }
public TMXReadWriteTest() : base("TileMaps/orthogonal-test2") { m_gid = CCTileGidAndFlags.EmptyTile; CCTileMapLayer layer = tileMap.LayerNamed("Layer 0"); layer.Antialiased = true; tileMap.Scale = (1); CCSprite tile0 = layer.ExtractTile(1, 63); CCSprite tile1 = layer.ExtractTile(2, 63); CCSprite tile2 = layer.ExtractTile(3, 62); //new CCPoint(1,62)); CCSprite tile3 = layer.ExtractTile(2, 62); tile0.AnchorPoint = (new CCPoint(0.5f, 0.5f)); tile1.AnchorPoint = (new CCPoint(0.5f, 0.5f)); tile2.AnchorPoint = (new CCPoint(0.5f, 0.5f)); tile3.AnchorPoint = (new CCPoint(0.5f, 0.5f)); CCMoveBy move = new CCMoveBy (0.5f, new CCPoint(0, 160)); CCRotateBy rotate = new CCRotateBy (2, 360); CCScaleBy scale = new CCScaleBy(2, 5); CCFadeOut opacity = new CCFadeOut (2); CCFadeIn fadein = new CCFadeIn (2); CCScaleTo scaleback = new CCScaleTo(1, 1); CCCallFuncN finish = new CCCallFuncN(removeSprite); CCSequence sequence = new CCSequence(move, rotate, scale, opacity, fadein, scaleback, finish); tile0.RunAction(sequence); tile1.RunAction(sequence); tile2.RunAction(sequence); tile3.RunAction(sequence); m_gid = layer.TileGIDAndFlags(0, 63); Schedule(updateCol, 2.0f); Schedule(repaintWithGID, 2.0f); Schedule(removeTiles, 1.0f); m_gid2 = CCTileGidAndFlags.EmptyTile; }
/// <summary> /// Adds the sprites to the region view. /// </summary> /// <param name="gid">The Gid.</param> private void AddSprites(CCTileGidAndFlags gid) { foreach (var tile in m_surroundedPositions) { m_sprites.Add(m_worldLayer.GetRegionViewHex(tile.RegionPosition).SetIndicatorGid(tile.CellPosition, gid)); } }
void SetBatchRenderedTileGID(int column, int row, CCTileGidAndFlags gidAndFlags) { int flattenedIndex = FlattenedTileIndex(column, row); CCTileGidAndFlags prevGid = TileGIDAndFlagsArray[flattenedIndex]; if (gidAndFlags != prevGid) { TileGIDAndFlagsArray[flattenedIndex] = gidAndFlags; if (prevGid.Gid == 0) { var drawBufferManager = GetDrawBufferManagerByGid(gidAndFlags.Gid); CCTileMapVertAndIndexBuffer drawBuffer = drawBufferManager.GetDrawBufferAtIndex(flattenedIndex); drawBuffer.UpdateQuad(flattenedIndex, ref gidAndFlags, true); } else if (gidAndFlags.Gid == 0) { var oldDrawBufferManager = GetDrawBufferManagerByGid(prevGid.Gid); CCTileMapVertAndIndexBuffer drawBuffer = oldDrawBufferManager.GetDrawBufferAtIndex(flattenedIndex); drawBuffer.UpdateQuad(flattenedIndex, ref gidAndFlags, true); } else { var emptyTile = CCTileGidAndFlags.EmptyTile; var oldDrawBufferManager = GetDrawBufferManagerByGid(prevGid.Gid); CCTileMapVertAndIndexBuffer oldDrawBuffer = oldDrawBufferManager.GetDrawBufferAtIndex(flattenedIndex); oldDrawBuffer.UpdateQuad(flattenedIndex, ref emptyTile, true); var drawBufferManager = GetDrawBufferManagerByGid(gidAndFlags.Gid); CCTileMapVertAndIndexBuffer drawBuffer = drawBufferManager.GetDrawBufferAtIndex(flattenedIndex); drawBuffer.UpdateQuad(flattenedIndex, ref gidAndFlags, true); } } }
public void SetTileGID(CCTileGidAndFlags gidAndFlags, CCTileMapCoordinates tileCoords) { if (gidAndFlags.Gid == 0) { RemoveTile(tileCoords); return; } if (AreValidTileCoordinates(tileCoords) == false) { Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile coordinates row: {0} column: {1}", tileCoords.Row, tileCoords.Column)); return; } CCTileGidAndFlags currentGID = TileGIDAndFlags(tileCoords); if (currentGID == gidAndFlags) return; CCTileMapDrawBufferManager drawBufferManager = GetDrawBufferManagerByGid(gidAndFlags.Gid); if (drawBufferManager == null) { foreach (CCTileSetInfo tileSetInfo in mapInfo.Tilesets) { if (tileSetInfo.FirstGid <= gidAndFlags.Gid && tileSetInfo.LastGid >= gidAndFlags.Gid) { drawBufferManager = InitialiseDrawBuffer(tileSetInfo); break; } } if (drawBufferManagers == null) { Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile grid id: {0}", gidAndFlags.Gid)); return; } drawBufferManagers.Add(drawBufferManager); visibleTileRangeDirty = true; } SetBatchRenderedTileGID(tileCoords.Column, tileCoords.Row, gidAndFlags); }
public void UpdateQuad(int flattenedTileIndex, ref CCTileGidAndFlags tileGID, bool updateBuffer = false) { int adjustedTileIndex = flattenedTileIndex - TileStartIndex; int adjustedStartVertexIndex = adjustedTileIndex * NumOfCornersPerQuad; if (tileGID.Gid == 0) { for (int i = 0; i < NumOfCornersPerQuad; i++) QuadsVertexBuffer.Data[adjustedStartVertexIndex + i] = new CCV3F_C4B_T2F(); if (updateBuffer) QuadsVertexBuffer.UpdateBuffer(adjustedStartVertexIndex, NumOfCornersPerQuad); return; } else if (tileGID.Gid < TileSetInfo.FirstGid || tileGID.Gid > TileSetInfo.LastGid) { return; } float left, right, top, bottom, vertexZ; vertexZ = TileMapLayer.TileVertexZ(flattenedTileIndex); CCSize tileSize = TileSetInfo.TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios; CCSize texSize = TileSetInfo.TilesheetSize; CCPoint tilePos = TileMapLayer.TilePosition(flattenedTileIndex); var quadVertexData = QuadsVertexBuffer.Data; var quad = new CCV3F_C4B_T2F_Quad(); // vertices if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0) { left = tilePos.X; right = tilePos.X + tileSize.Height; bottom = tilePos.Y + tileSize.Width; top = tilePos.Y; } else { left = tilePos.X; right = tilePos.X + tileSize.Width; bottom = tilePos.Y + tileSize.Height; top = tilePos.Y; } float temp; if ((tileGID.Flags & CCTileFlags.Vertical) != 0) { temp = top; top = bottom; bottom = temp; } if ((tileGID.Flags & CCTileFlags.Horizontal) != 0) { temp = left; left = right; right = temp; } if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0) { // FIXME: not working correcly quad.BottomLeft.Vertices = new CCVertex3F(left, bottom, vertexZ); quad.BottomRight.Vertices = new CCVertex3F(left, top, vertexZ); quad.TopLeft.Vertices = new CCVertex3F(right, bottom, vertexZ); quad.TopRight.Vertices = new CCVertex3F(right, top, vertexZ); } else { quad.BottomLeft.Vertices = new CCVertex3F(left, bottom, vertexZ); quad.BottomRight.Vertices = new CCVertex3F(right, bottom, vertexZ); quad.TopLeft.Vertices = new CCVertex3F(left, top, vertexZ); quad.TopRight.Vertices = new CCVertex3F(right, top, vertexZ); } // texcoords CCRect tileTexture = TileSetInfo.TextureRectForGID(tileGID.Gid); left = ((tileTexture.Origin.X) / texSize.Width) + 0.5f / texSize.Width; right = left + ((tileTexture.Size.Width) / texSize.Width) - 1.0f / texSize.Width; bottom = ((tileTexture.Origin.Y) / texSize.Height) + 0.5f / texSize.Height; top = bottom + ((tileTexture.Size.Height) / texSize.Height) - 1.0f / texSize.Height; quad.BottomLeft.TexCoords = new CCTex2F(left, bottom); quad.BottomRight.TexCoords = new CCTex2F(right, bottom); quad.TopLeft.TexCoords = new CCTex2F(left, top); quad.TopRight.TexCoords = new CCTex2F(right, top); quad.BottomLeft.Colors = CCColor4B.White; quad.BottomRight.Colors = CCColor4B.White; quad.TopLeft.Colors = CCColor4B.White; quad.TopRight.Colors = CCColor4B.White; QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex] = quad.TopLeft; QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 1] = quad.BottomLeft; QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 2] = quad.TopRight; QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 3] = quad.BottomRight; if (updateBuffer) QuadsVertexBuffer.UpdateBuffer(adjustedStartVertexIndex, NumOfCornersPerQuad); }
public void ReplaceTileGIDQuad(short originalGid, short gidOfQuadToUse) { var indices = IndexBuffer.Data.Elements; for (int i = 0, N = IndexBufferSize; i < N; i += 6) { int tileIndex = (indices[i] / NumOfCornersPerQuad) + TileStartIndex; var gidAndFlag = TileMapLayer.TileGIDAndFlagsArray[tileIndex]; /* So here we're updating the underlying quadvertexbuffer after each quad change The alternative is to determine the min/max tile index and call QuadsVertexBuffer.UpdateBuffer() over that range. The assumption is that replacing tile gid quads is primarily used for animating tiles that share a common original gid. In particular, we would expect that animated tiles are small in number and/or sparsely spread out across the tile map e.g. Water tiles/trees/character/light source etc. So it's likely updating over a range would unnecessarily update a large number of unchanged quads */ if (gidAndFlag.Gid == originalGid) { var replacementQuadGid = new CCTileGidAndFlags(gidOfQuadToUse, gidAndFlag.Flags); UpdateQuad(tileIndex, ref replacementQuadGid, true); } } }
/// <summary> /// Sets the Definitions to tile GIDs. /// </summary> /// <returns>The tile GID.</returns> /// <param name="definition">Definition which GID is wanted.</param> /// <param name="sort">Sort, if it's a menu, enemy or normal.</param> public CCTileGidAndFlags DefinitionToTileGid(Definition definition, Sort sort = Sort.Normal) { CCTileGidAndFlags gid; gid = new CCTileGidAndFlags(Common.Constants.TerrainGid.INVALID); if (definition.Category == Core.Models.Definitions.Category.Terrain) { var terrainDefinition = definition as TerrainDefinition; m_terrainsGid.TryGetValue(terrainDefinition.SubType, out gid); } else { var unitDefinition = definition as UnitDefinition; switch (sort) { case Sort.Normal: m_entitiesGid.TryGetValue(unitDefinition.SubType, out gid); break; case Sort.Enemy: m_enemyEntitiesGid.TryGetValue(unitDefinition.SubType, out gid); break; case Sort.Menu: m_menuEntitiesGid.TryGetValue(unitDefinition.SubType, out gid); break; } } return gid; }
void UpdateQuadAt(int tileCoordX, int tileCoordY, bool updateBuffer = true) { int flattenedTileIndex = FlattenedTileIndex(tileCoordX, tileCoordY); CCTileGidAndFlags tileGID = tileGIDAndFlagsArray[flattenedTileIndex]; CCTileMapVertAndIndexBuffer drawBuffer = drawBufferManager.GetDrawBufferAtIndex(flattenedTileIndex); int adjustedTileIndex = flattenedTileIndex - drawBuffer.TileStartIndex; if (tileGID.Gid == 0) { drawBuffer.QuadsVertexBuffer.Data[adjustedTileIndex] = new CCV3F_C4B_T2F_Quad(); if (updateBuffer) { drawBuffer.QuadsVertexBuffer.UpdateBuffer(adjustedTileIndex, 1); } return; } float left, right, top, bottom, vertexZ; vertexZ = TileVertexZ(tileCoordX, tileCoordY); CCSize tileSize = TileSetInfo.TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios; CCSize texSize = TileSetInfo.TilesheetSize; CCPoint tilePos = TilePosition(tileCoordX, tileCoordY); var quad = drawBuffer.QuadsVertexBuffer.Data[adjustedTileIndex]; // vertices if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0) { left = tilePos.X; right = tilePos.X + tileSize.Height; bottom = tilePos.Y + tileSize.Width; top = tilePos.Y; } else { left = tilePos.X; right = tilePos.X + tileSize.Width; bottom = tilePos.Y + tileSize.Height; top = tilePos.Y; } float temp; if ((tileGID.Flags & CCTileFlags.Vertical) != 0) { temp = top; top = bottom; bottom = temp; } if ((tileGID.Flags & CCTileFlags.Horizontal) != 0) { temp = left; left = right; right = temp; } if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0) { // FIXME: not working correcly quad.BottomLeft.Vertices = new CCVertex3F(left, bottom, vertexZ); quad.BottomRight.Vertices = new CCVertex3F(left, top, vertexZ); quad.TopLeft.Vertices = new CCVertex3F(right, bottom, vertexZ); quad.TopRight.Vertices = new CCVertex3F(right, top, vertexZ); } else { quad.BottomLeft.Vertices = new CCVertex3F(left, bottom, vertexZ); quad.BottomRight.Vertices = new CCVertex3F(right, bottom, vertexZ); quad.TopLeft.Vertices = new CCVertex3F(left, top, vertexZ); quad.TopRight.Vertices = new CCVertex3F(right, top, vertexZ); } // texcoords CCRect tileTexture = TileSetInfo.TextureRectForGID(tileGID.Gid); left = ((tileTexture.Origin.X) / texSize.Width) + 0.5f / texSize.Width; right = left + ((tileTexture.Size.Width) / texSize.Width) - 1.0f / texSize.Width; bottom = ((tileTexture.Origin.Y) / texSize.Height) + 0.5f / texSize.Height; top = bottom + ((tileTexture.Size.Height) / texSize.Height) - 1.0f / texSize.Height; quad.BottomLeft.TexCoords = new CCTex2F(left, bottom); quad.BottomRight.TexCoords = new CCTex2F(right, bottom); quad.TopLeft.TexCoords = new CCTex2F(left, top); quad.TopRight.TexCoords = new CCTex2F(right, top); quad.BottomLeft.Colors = CCColor4B.White; quad.BottomRight.Colors = CCColor4B.White; quad.TopLeft.Colors = CCColor4B.White; quad.TopRight.Colors = CCColor4B.White; drawBuffer.QuadsVertexBuffer.Data[adjustedTileIndex] = quad; if (updateBuffer) { drawBuffer.QuadsVertexBuffer.UpdateBuffer(adjustedTileIndex, 1); } }
public void UpdateQuad(int flattenedTileIndex, ref CCTileGidAndFlags tileGID, bool updateBuffer = false) { int adjustedTileIndex = flattenedTileIndex - TileStartIndex; int adjustedStartVertexIndex = adjustedTileIndex * NumOfCornersPerQuad; if (tileGID.Gid == 0) { for (int i = 0; i < NumOfCornersPerQuad; i++) { QuadsVertexBuffer.Data[adjustedStartVertexIndex + i] = new CCV3F_C4B_T2F(); } if (updateBuffer) { QuadsVertexBuffer.UpdateBuffer(adjustedStartVertexIndex, NumOfCornersPerQuad); } return; } else if (tileGID.Gid < TileSetInfo.FirstGid || tileGID.Gid > TileSetInfo.LastGid) { return; } float left, right, top, bottom, vertexZ; vertexZ = TileMapLayer.TileVertexZ(flattenedTileIndex); CCSize tileSize = TileSetInfo.TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios; CCSize texSize = TileSetInfo.TilesheetSize; CCPoint tilePos = TileMapLayer.TilePosition(flattenedTileIndex); var quadVertexData = QuadsVertexBuffer.Data; var quad = new CCV3F_C4B_T2F_Quad(); // vertices if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0) { left = tilePos.X; right = tilePos.X + tileSize.Height; bottom = tilePos.Y + tileSize.Width; top = tilePos.Y; } else { left = tilePos.X; right = tilePos.X + tileSize.Width; bottom = tilePos.Y + tileSize.Height; top = tilePos.Y; } float temp; if ((tileGID.Flags & CCTileFlags.Vertical) != 0) { temp = top; top = bottom; bottom = temp; } if ((tileGID.Flags & CCTileFlags.Horizontal) != 0) { temp = left; left = right; right = temp; } if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0) { // FIXME: not working correcly quad.BottomLeft.Vertices = new CCVertex3F(left, bottom, vertexZ); quad.BottomRight.Vertices = new CCVertex3F(left, top, vertexZ); quad.TopLeft.Vertices = new CCVertex3F(right, bottom, vertexZ); quad.TopRight.Vertices = new CCVertex3F(right, top, vertexZ); } else { quad.BottomLeft.Vertices = new CCVertex3F(left, bottom, vertexZ); quad.BottomRight.Vertices = new CCVertex3F(right, bottom, vertexZ); quad.TopLeft.Vertices = new CCVertex3F(left, top, vertexZ); quad.TopRight.Vertices = new CCVertex3F(right, top, vertexZ); } // texcoords CCRect tileTexture = TileSetInfo.TextureRectForGID(tileGID.Gid); left = ((tileTexture.Origin.X) / texSize.Width) + 0.5f / texSize.Width; right = left + ((tileTexture.Size.Width) / texSize.Width) - 1.0f / texSize.Width; bottom = ((tileTexture.Origin.Y) / texSize.Height) + 0.5f / texSize.Height; top = bottom + ((tileTexture.Size.Height) / texSize.Height) - 1.0f / texSize.Height; quad.BottomLeft.TexCoords = new CCTex2F(left, bottom); quad.BottomRight.TexCoords = new CCTex2F(right, bottom); quad.TopLeft.TexCoords = new CCTex2F(left, top); quad.TopRight.TexCoords = new CCTex2F(right, top); quad.BottomLeft.Colors = CCColor4B.White; quad.BottomRight.Colors = CCColor4B.White; quad.TopLeft.Colors = CCColor4B.White; quad.TopRight.Colors = CCColor4B.White; QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex] = quad.TopLeft; QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 1] = quad.BottomLeft; QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 2] = quad.TopRight; QuadsVertexBuffer.Data.Elements[adjustedStartVertexIndex + 3] = quad.BottomRight; if (updateBuffer) { QuadsVertexBuffer.UpdateBuffer(adjustedStartVertexIndex, NumOfCornersPerQuad); } }
public CCSprite ExtractTile(int column, int row, bool addToTileMapLayer = true) { if (!AreValidTileCoordinates(column, row)) { return(null); } CCTileGidAndFlags gidAndFlags = TileGIDAndFlags(column, row); int flattendedIndex = FlattenedTileIndex(column, row); CCTileSetInfo tileSetInfo = GetDrawBufferManagerByGid(gidAndFlags.Gid).TileSetInfo; CCRect texRect = tileSetInfo.TextureRectForGID(gidAndFlags.Gid); CCSprite tileSprite = new CCSprite(tileSetInfo.Texture, texRect); tileSprite.ContentSize = texRect.Size * CCTileMapLayer.DefaultTexelToContentSizeRatios; tileSprite.Position = TilePosition(column, row); tileSprite.VertexZ = TileVertexZ(column, row); tileSprite.AnchorPoint = CCPoint.Zero; tileSprite.Opacity = Opacity; tileSprite.FlipX = false; tileSprite.FlipY = false; tileSprite.Rotation = 0.0f; if ((gidAndFlags.Flags & CCTileFlags.TileDiagonal) != 0) { CCSize halfContentSize = tileSprite.ContentSize * 0.5f; tileSprite.AnchorPoint = CCPoint.AnchorMiddle; tileSprite.Position += new CCPoint(halfContentSize.Width, halfContentSize.Height); CCTileFlags horAndVertFlag = gidAndFlags.Flags & (CCTileFlags.Horizontal | CCTileFlags.Vertical); // Handle the 4 diagonally flipped states. if (horAndVertFlag == CCTileFlags.Horizontal) { tileSprite.Rotation = 90.0f; } else if (horAndVertFlag == CCTileFlags.Vertical) { tileSprite.Rotation = 270.0f; } else if (horAndVertFlag == (CCTileFlags.Vertical | CCTileFlags.Horizontal)) { tileSprite.Rotation = 90.0f; tileSprite.FlipX = true; } else { tileSprite.Rotation = 270.0f; tileSprite.FlipX = true; } } else { if ((gidAndFlags.Flags & CCTileFlags.Horizontal) != 0) { tileSprite.FlipX = true; } if ((gidAndFlags.Flags & CCTileFlags.Vertical) != 0) { tileSprite.FlipY = true; } } if (addToTileMapLayer) { AddChild(tileSprite, flattendedIndex, flattendedIndex); } RemoveTile(column, row); return(tileSprite); }
internal static CCTileGidAndFlags DecodeGidAndFlags(uint encodedGidAndFlags) { CCTileGidAndFlags gidAndFlags= new CCTileGidAndFlags(0, 0); gidAndFlags.Gid = (short)(encodedGidAndFlags & CCTileMapFileEncodedTileFlags.FlippedMask); if (gidAndFlags.Gid != 0) { gidAndFlags.Gid = gidAndFlags.Gid; } if((encodedGidAndFlags & CCTileMapFileEncodedTileFlags.Horizontal) != 0) gidAndFlags.Flags = gidAndFlags.Flags | CCTileFlags.Horizontal; if((encodedGidAndFlags & CCTileMapFileEncodedTileFlags.Vertical) != 0) gidAndFlags.Flags = gidAndFlags.Flags | CCTileFlags.Vertical; if ((encodedGidAndFlags & CCTileMapFileEncodedTileFlags.TileDiagonal) != 0) gidAndFlags.Flags = gidAndFlags.Flags | CCTileFlags.TileDiagonal; return gidAndFlags; }
/// <summary> /// Draws the indicator on the Map /// </summary> /// <param name="coord">The Center Position.</param> /// <param name="range">The Range.</param> /// <param name="area">The Area Type.</param> public void ShowUnitIndicator(PositionI coord, int range, TileTouchHandler.Area area) { var gid = new CCTileGidAndFlags(Client.Common.Constants.HelperSpritesGid.GREENINDICATOR); m_areaIndicators.TryGetValue(area, out gid); if (area == TileTouchHandler.Area.Movement) { var indi = new Core.Controllers.AStar_Indicator.Indicator(coord, range, GameAppDelegate.Account.ID); m_surroundedPositions = indi.FindPossiblePositions(); } AddSprites(gid); }
public static bool Equal(ref CCTileGidAndFlags gid1, ref CCTileGidAndFlags gid2) { return ((gid1.Gid == gid2.Gid) && (gid1.Flags == gid2.Flags)); }
/// <summary> /// Shows the building indicator. /// </summary> /// <param name="coord">The positionI.</param> /// <param name="area">The ownership of the area.</param> public void ShowBuildingIndicator(PositionI coord, TileTouchHandler.Area area) { var gid = new CCTileGidAndFlags(Client.Common.Constants.HelperSpritesGid.GREENINDICATOR); m_areaIndicators.TryGetValue(area, out gid); var buildings = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(coord.RegionPosition) .GetEntity(coord.CellPosition).Owner.TerritoryBuildings.Keys; int range; foreach (var building in buildings) { var entity = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(building.RegionPosition).GetEntity(building.CellPosition); if (entity.Definition.SubType == Core.Models.Definitions.EntityType.Headquarter) { range = Core.Models.Constants.HEADQUARTER_TERRITORY_RANGE; } else { range = Core.Models.Constants.GUARDTOWER_TERRITORY_RANGE; } var surroundedPositions = LogicRules.GetSurroundedPositions(building, range); m_surroundedPositions.UnionWith(surroundedPositions); } AddSprites(gid); }
public bool Equals(CCTileGidAndFlags gidAndFlag) { return this == gidAndFlag; }
public CCTileGidAndFlags TileGIDAndFlags(int column, int row) { CCTileGidAndFlags tileGIDAndFlags = new CCTileGidAndFlags(0,0); if(AreValidTileCoordinates(column, row)) { int flattenedIndex = FlattenedTileIndex(column, row); tileGIDAndFlags = tileGIDAndFlagsArray[flattenedIndex]; } return tileGIDAndFlags; }
/// <summary> /// Sets the major menu. /// </summary> /// <param name="menuType">The menu type.</param> private void SetMajorMenu(MenuType menuType) { var gids = new short[6]; gids[5] = Client.Common.Constants.BuildingMenuGid.MILITARY; gids[0] = Client.Common.Constants.BuildingMenuGid.RESOURCES; gids[1] = Client.Common.Constants.BuildingMenuGid.STORAGE; gids[2] = Client.Common.Constants.BuildingMenuGid.CIVIL; gids[3] = Client.Common.Constants.BuildingMenuGid.BUILDINGPLACEHOLDER; gids[4] = Client.Common.Constants.BuildingMenuGid.CANCEL; var surroundedPos = LogicRules.GetSurroundedFields(m_center); for (var index = 0; index < surroundedPos.Length; ++index) { var pos = surroundedPos[index]; var gid = new CCTileGidAndFlags(gids[index]); m_sprites.Add(pos, m_worldLayer.GetRegionViewHex(pos.RegionPosition).SetMenuTile(pos, gid)); m_baseMenuPositions[pos] = gid; } }
void SetBatchRenderedTileGID(int column, int row, CCTileGidAndFlags gidAndFlags) { int flattenedIndex = FlattenedTileIndex(column, row); CCTileGidAndFlags prevGid = tileGIDAndFlagsArray[flattenedIndex]; if(gidAndFlags != prevGid) { tileGIDAndFlagsArray[flattenedIndex] = gidAndFlags; UpdateQuadAt(column, row); } }
public bool Equals(CCTileGidAndFlags gidAndFlag) { return(this == gidAndFlag); }
/// <summary> /// Sets the indicator gid. /// </summary> /// <returns>The indicator gid.</returns> /// <param name="cellPos">The cell position.</param> /// <param name="gid">The gid.</param> public CCSprite SetIndicatorGid(CellPosition cellPos, CCTileGidAndFlags gid) { m_indicatorLayer.SetTileGID(gid, new CCTileMapCoordinates(cellPos.CellX, cellPos.CellY)); var sprite = m_indicatorLayer.ExtractTile(new CCTileMapCoordinates(cellPos.CellX, cellPos.CellY), true); sprite.Opacity = HelperSpritesGid.INDICATOR_OPACITY; return sprite; }
public static bool Equal(ref CCTileGidAndFlags gid1, ref CCTileGidAndFlags gid2) { return((gid1.Gid == gid2.Gid) && (gid1.Flags == gid2.Flags)); }