當前位置: 首頁>>代碼示例>>C#>>正文


C# Sprite.save_Position方法代碼示例

本文整理匯總了C#中Microsoft.Xna.Framework.Graphics.Sprite.save_Position方法的典型用法代碼示例。如果您正苦於以下問題:C# Sprite.save_Position方法的具體用法?C# Sprite.save_Position怎麽用?C# Sprite.save_Position使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Xna.Framework.Graphics.Sprite的用法示例。


在下文中一共展示了Sprite.save_Position方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Check_Border_colision

        /// <summary>
        /// Determines if the obj passed is hitting the borders of the game world screen
        /// and re-sets the position of the obj and its bounding box.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="obj"></param>
        public static void Check_Border_colision(GraphicsDeviceManager graphics , Sprite obj)
        {
            float MaxX = graphics.GraphicsDevice.Viewport.Width - obj.get_Texture().Width * obj.get_Scale().X;
            float MinX = 0;
            float MaxY = graphics.GraphicsDevice.Viewport.Height - obj.get_Texture().Height * obj.get_Scale().Y;
            float MinY = 0;

            //Check for bounce
            if (obj.Position.X > MaxX)          // Right border check
            {
                obj.save_Position();

                obj.Direction.X *= -1;
                obj.Position.X = MaxX; // back up  to meet colision surface
                obj.set_box(); // allow boundingbox to follow sprite

                if (obj.Type == "Ball") // Only produce sound if the obj is a Ball
                  Breakout.theSoundBank.PlayCue("BorderHit");

            }

            else if (obj.Position.X < MinX)     // Left border check
            {
                obj.save_Position();

                obj.Direction.X *= -1;
                obj.Position.X = MinX;
                obj.set_box();
                if (obj.Type == "Ball") // Only produce sound if the obj is a Ball
                 Breakout.theSoundBank.PlayCue("BorderHit");
            }

            if (obj.Position.Y > MaxY)          // Bottom border check
            {
                obj.save_Position();

                obj.Direction.Y *= -1;
                obj.Position.Y = MaxY;
                obj.set_box();
                if (obj.Type == "Ball") // Only produce sound if the obj is a Ball
                   Breakout.theSoundBank.PlayCue("BorderHit");

            }

            else if (obj.Position.Y < MinY)     // Top border check
            {
                obj.save_Position();

                obj.Direction.Y *= -1;
                obj.Position.Y = MinY;
                obj.set_box();
                if (obj.Type == "Ball") // Only produce sound if the obj is a Ball
                   Breakout.theSoundBank.PlayCue("BorderHit");
            }
        }
開發者ID:JoseLSG,項目名稱:2008-breakout-clone,代碼行數:61,代碼來源:Collisions.cs


注:本文中的Microsoft.Xna.Framework.Graphics.Sprite.save_Position方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。