当前位置: 首页>>代码示例>>C#>>正文


C# SpriteEffects.HasFlag方法代码示例

本文整理汇总了C#中SpriteEffects.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# SpriteEffects.HasFlag方法的具体用法?C# SpriteEffects.HasFlag怎么用?C# SpriteEffects.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SpriteEffects的用法示例。


在下文中一共展示了SpriteEffects.HasFlag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GUIDrawSprite

        public void GUIDrawSprite(Texture2D texture, Rectangle destinationRectangle,
            Rectangle? sourceRectangle = null, Color? color = null, SpriteEffects effects = SpriteEffects.None)
        {
            if (texture == null)
                return;
            Vector4 dest = new Vector4(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Right, destinationRectangle.Bottom);
            Vector4 srcDelta = new Vector4();
            if (sourceRectangle == null)
                sourceRectangle = new Rectangle(0, 0, texture.Width, texture.Height);

            // clipping
            if (dest.X < m_GUIClipRect.X)
            {
                if (dest.Z < m_GUIClipRect.X)
                    return;
                float delta = m_GUIClipRect.X - dest.X;
                dest.X += delta;
                srcDelta.X = delta / destinationRectangle.Width;
            }
            if (dest.Z > m_GUIClipRect.Z)
            {
                if (dest.X > m_GUIClipRect.Z)
                    return;
                float delta = m_GUIClipRect.Z - dest.Z;
                dest.Z += delta;
                srcDelta.Z = delta / destinationRectangle.Width;
            }
            if (dest.Y < m_GUIClipRect.Y)
            {
                if (dest.W < m_GUIClipRect.Y)
                    return;
                float delta = m_GUIClipRect.Y - dest.Y;
                dest.Y += delta;
                srcDelta.Y = delta / destinationRectangle.Width;
            }
            if (dest.W > m_GUIClipRect.W)
            {
                if (dest.Y > m_GUIClipRect.W)
                    return;
                float delta = m_GUIClipRect.W - dest.W;
                dest.W += delta;
                srcDelta.W = delta / destinationRectangle.Width;
            }

            Vector4 source = new Vector4(
                sourceRectangle.Value.X, sourceRectangle.Value.Y,
                sourceRectangle.Value.Right, sourceRectangle.Value.Bottom);

            if (effects.HasFlag(SpriteEffects.FlipHorizontally))
            {
                float x = source.X;
                source.X = source.Z;
                source.Z = x;
            }
            if (effects.HasFlag(SpriteEffects.FlipVertically))
            {
                float y = source.Y;
                source.Y = source.W;
                source.W = y;
            }

            float width = texture.Width;
            float height = texture.Height;

            source.X /= width;
            source.Y /= height;
            source.Z /= width;
            source.W /= height;

            source.X += srcDelta.X * ((float)sourceRectangle.Value.Width / width);
            source.Y += srcDelta.Y * ((float)sourceRectangle.Value.Height / height);
            source.Z += srcDelta.Z * ((float)sourceRectangle.Value.Width / width);
            source.W += srcDelta.W * ((float)sourceRectangle.Value.Height / height);

            source.Y -= (0.5f / height);
            source.W -= (0.5f / height);

            Shape quad = Shape.CreateQuad(
                new Vector3(destinationRectangle.X, destinationRectangle.Y, 0),
                new Vector2(destinationRectangle.Width, destinationRectangle.Height),
                source, color);

            List<VertexPositionTextureHueExtra> vertexList = InternalGetVertexList();
            for (int i = 0; i < quad.Vertices.Length; i++)
            {
                quad.Vertices[i].Position.Z = m_zOffset;
                vertexList.Add(quad.Vertices[i]);
            }
            // increment z offset for the spritebatch.
            m_zOffset++;

            m_DrawCommands.Add(new TextureAndVertexList(texture, vertexList));
        }
开发者ID:FreeReign,项目名称:UltimaXNA,代码行数:93,代码来源:YSpriteBatch_GUI.cs

示例2: FlipLocal

 public void FlipLocal(SpriteEffects flip)
 {
     if (SelectedPartEntities.Count <= 0) return;
     foreach(var item in SelectedPartEntities.Select(e => e.GetComponent<IShipPartComponent>().Part))
     {
         //if(item is Hull)
         //{
         //    var hull = (Hull)item;
         //    hull.SpriteEffect ^= fx;
         //}
         if (flip.HasFlag(SpriteEffects.FlipHorizontally)) item.Transform.Position *= new Vector2(-1, 1);
         if (flip.HasFlag(SpriteEffects.FlipVertically)) item.Transform.Position *= new Vector2(1, -1);
     }
 }
开发者ID:raycrasher,项目名称:Fell-Sky,代码行数:14,代码来源:ShipEditorService.cs

示例3: FlipGroup

        public void FlipGroup(SpriteEffects flip)
        {
            if (flip == SpriteEffects.None) return;
            if (SelectedPartEntities.Count <= 0) return;
            var centroid = SelectedPartEntities.Aggregate(Vector2.Zero, (ta, e) => ta += e.GetComponent<Transform>().Position) / SelectedPartEntities.Count;
            foreach (var item in SelectedPartEntities.Select(e => e.GetComponent<IShipPartComponent>().Part))
            {
                //if (item is Hull)
                //{
                //    var hull = (Hull)item;
                //    hull.SpriteEffect ^= flip;
                //}

                if (flip.HasFlag(SpriteEffects.FlipHorizontally)) item.Transform.Scale *= new Vector2(-1, 1);
                if (flip.HasFlag(SpriteEffects.FlipVertically)) item.Transform.Scale *= new Vector2(1, -1);

                if (flip == SpriteEffects.FlipVertically)
                {
                    item.Transform.Position = new Vector2(
                        item.Transform.Position.X,
                        item.Transform.Position.Y - (item.Transform.Position.Y - centroid.Y)*2
                        );
                } else if(flip == SpriteEffects.FlipHorizontally)
                {
                    item.Transform.Position = new Vector2(
                        item.Transform.Position.X - (item.Transform.Position.X - centroid.X) * 2,
                        item.Transform.Position.Y
                        );
                }

            }
        }
开发者ID:raycrasher,项目名称:Fell-Sky,代码行数:32,代码来源:ShipEditorService.cs

示例4: Draw

        public void Draw(Texture2D texture, Rectangle? sourceRect, Rectangle destRect, Color4 color, Vector2 scale, float depth = 0, SpriteEffects effects = SpriteEffects.None)
        {
            // Flush if the current texture is valid
            // and the new texture differs from the current texture
            if (CurrentTexture.TextureId != -1 && texture.TextureId != CurrentTexture.TextureId)
                Flush ();

            // Set the current texture to the new texture
            CurrentTexture = texture;

            // Flush if the vertex or index counts exceeds the maximum
            if (indexCount + 6 >= MAX_INDICES || vertexCount + 4 >= MAX_VERTICES)
                Flush ();

            // Construct source rectangle
            Rectangle source = sourceRect ?? new Rectangle (0, 0, texture.Width, texture.Height);

            // Decompose destination rectangle
            float x = destRect.X;
            float y = destRect.Y;
            float w = destRect.Width * scale.X;
            float h = destRect.Height * scale.Y;

            // Decompose source rectangle
            float srcX = source.X;
            float srcY = source.Y;
            float srcW = source.Width;
            float srcH = source.Height;

            var topLeftCoord = new Vector2 (
                x: srcX / (float) texture.Width,
                y: srcY / (float) texture.Height);

            var topRightCoord = new Vector2 (
                x: (srcX + srcW) / (float) texture.Width,
                y: srcY / (float) texture.Height);

            var bottomLeftCoord = new Vector2 (
                x: srcX / (float) texture.Width,
                y: (srcY + srcH) / (float) texture.Height);

            var bottomRightCoord = new Vector2 (
                x: (srcX + srcW) / (float) texture.Width,
                y: (srcY + srcH) / (float) texture.Height);

            // Flip the texture horizontally if requested
            if (effects.HasFlag (SpriteEffects.FlipHorizontal)) {
                SwapVec (ref topLeftCoord, ref topRightCoord);
                SwapVec (ref bottomLeftCoord, ref bottomRightCoord);
            }

            // Flip the texture horizontally if requested
            if (effects.HasFlag (SpriteEffects.FlipVertical)) {
                SwapVec (ref topLeftCoord, ref bottomLeftCoord);
                SwapVec (ref topRightCoord, ref bottomRightCoord);
            }

            // Top left
            Vertices[vertexCount++] = new Vertex2D (
                new Vector3 (x, y, depth),
                topLeftCoord,
                color
            );

            // Top right
            Vertices[vertexCount++] = new Vertex2D (
                new Vector3 (x + w, y, depth),
                topRightCoord,
                color
            );

            // Bottom left
            Vertices[vertexCount++] = new Vertex2D (
                new Vector3 (x, y + h, depth),
                bottomLeftCoord,
                color
            );

            // Bottom right
            Vertices[vertexCount++] = new Vertex2D (
                new Vector3 (x + w, y + h, depth),
                bottomRightCoord,
                color
            );

            // Increment the index count
            indexCount += 6;
        }
开发者ID:splitandthechro,项目名称:nginz,代码行数:88,代码来源:SpriteBatch.cs


注:本文中的SpriteEffects.HasFlag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。