Exemple #1
0
        public bool IsOrigin(Vector2Short uv)
        {
            if (uv == Vector2Short.Zero)
            {
                return(true);
            }

            var renderUV    = WorldRenderXna.GetRenderUV((ushort)Id, uv.X, uv.Y);
            var frameSizeIx = GetFrameSizeIndex((short)renderUV.Y);
            var frameSize   = FrameSize[frameSizeIx];

            if (frameSizeIx == 0)
            {
                return(renderUV.X % ((TextureGrid.X + FrameGap.X) * frameSize.X) == 0 &&
                       renderUV.Y % ((TextureGrid.Y + FrameGap.Y) * frameSize.Y) == 0);
            }
            else
            {
                int y = 0;
                for (int i = 0; i < frameSizeIx; i++)
                {
                    y += FrameSize[i].Y * (TextureGrid.Y + FrameGap.Y);
                }
                return(renderUV.X % ((TextureGrid.X + FrameGap.X) * frameSize.X) == 0 && renderUV.Y == y);
            }
        }
        public bool IsOrigin(Vector2Short uv)
        {
            if (uv == Vector2Short.Zero)
            {
                return(true);
            }

            var renderUV  = WorldRenderXna.GetRenderUV((ushort)Id, uv.X, uv.Y);
            var frameSize = GetFrameSize((short)renderUV.Y);

            return(renderUV.X % ((TextureGrid.X + FrameGap.X) * frameSize.X) == 0 &&
                   renderUV.Y % ((TextureGrid.Y + FrameGap.Y) * frameSize.Y) == 0);
        }
        /// <summary>
        /// Get a Sprite from one of it's UV's
        /// </summary>
        /// <param name="uv"></param>
        /// <returns></returns>
        public KeyValuePair <int, SpriteSub> GetStyleFromUV(Vector2Short uv)
        {
            var renderUV = WorldRenderXna.GetRenderUV(Tile, uv.X, uv.Y);

            foreach (var kvp in Styles)
            {
                if (kvp.Value.UV == uv)
                {
                    return(kvp);
                }

                if (renderUV.X >= kvp.Value.UV.X &&
                    renderUV.Y >= kvp.Value.UV.Y &&
                    renderUV.X < kvp.Value.UV.X + (kvp.Value.SizePixelsInterval.X * kvp.Value.SizeTiles.X) &&
                    renderUV.Y < kvp.Value.UV.Y + (kvp.Value.SizePixelsInterval.Y * kvp.Value.SizeTiles.Y))
                {
                    return(kvp);
                }
            }
            return(default);