Ejemplo n.º 1
0
        void flipIt(float dt)
        {
            CCTileMapLayer layer = tileMap.LayerNamed("Layer 0");

            //blue diamond
            var tileCoord = new CCTileMapCoordinates(1, 10);

            CCTileGidAndFlags gidAndFlags = layer.TileGIDAndFlags(tileCoord);
            CCTileFlags       flags       = gidAndFlags.Flags;
            short             GID         = gidAndFlags.Gid;

            // Vertical
            if ((flags & CCTileFlags.Vertical) != 0)
            {
                flags &= ~CCTileFlags.Vertical;
            }
            else
            {
                flags |= CCTileFlags.Vertical;
            }


            layer.SetTileGID(new CCTileGidAndFlags(GID, flags), tileCoord);


            tileCoord   = new CCTileMapCoordinates(1, 8);
            gidAndFlags = layer.TileGIDAndFlags(tileCoord);
            GID         = gidAndFlags.Gid;
            flags       = gidAndFlags.Flags;

            // Vertical
            if ((flags & CCTileFlags.Vertical) != 0)
            {
                flags &= ~CCTileFlags.Vertical;
            }
            else
            {
                flags |= CCTileFlags.Vertical;
            }

            layer.SetTileGID(new CCTileGidAndFlags(GID, flags), tileCoord);

            tileCoord   = new CCTileMapCoordinates(2, 8);
            gidAndFlags = layer.TileGIDAndFlags(tileCoord);
            GID         = gidAndFlags.Gid;
            flags       = gidAndFlags.Flags;

            // Horizontal
            if ((flags & CCTileFlags.Horizontal) != 0)
            {
                flags &= ~CCTileFlags.Horizontal;
            }
            else
            {
                flags |= CCTileFlags.Horizontal;
            }

            layer.SetTileGID(new CCTileGidAndFlags(GID, flags), tileCoord);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public CCTileGidAndFlags(short gid, CCTileFlags flags) : this()
 {
     Gid   = gid;
     Flags = flags;
 }
Ejemplo n.º 4
0
 public CCTileGidAndFlags(short gid, CCTileFlags flags) : this()
 {
     Gid = gid;
     Flags = flags;
 }