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


C# Framework.Vector2類代碼示例

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


Vector2類屬於Microsoft.Xna.Framework命名空間,在下文中一共展示了Vector2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Draw

        public override void Draw(GameTime gameTime)
        {
            Vector3 direction;
            Vector3.Subtract(ref destination, ref source, out direction);

            spriteBatch.Begin();

            Vector3 innerVector;
            Vector3 outerVector;
            Vector3.Multiply (ref direction, innerDist, out outerVector);
            Vector3.Multiply(ref direction, outerDist, out innerVector);
            Vector3.Add(ref source, ref outerVector, out outerVector);
            Vector3.Add(ref source, ref innerVector, out innerVector);
            Vector2 outerPosition = new Vector2(outerVector.X, outerVector.Y);
            Vector2 innerPosition = new Vector2(innerVector.X, innerVector.Y);

            Vector2 offset = new Vector2(outer.Width, outer.Height);
            Vector2.Multiply(ref offset, 0.5f, out offset);
            Vector2.Subtract(ref outerPosition, ref offset, out outerPosition);
            Vector2.Subtract(ref innerPosition, ref offset, out innerPosition);

            spriteBatch.Draw(inner, innerPosition, targetColor);
            spriteBatch.Draw(outer, outerPosition, targetColor);

            spriteBatch.End();

            base.Draw(gameTime);
        }
開發者ID:kmatzen,項目名稱:EECS-494-Final-Project,代碼行數:28,代碼來源:Reticle.cs

示例2: Set

 public void Set(float x, float y, float w, float h, Color color, Vector2 texCoordTL, Vector2 texCoordBR)
 {
   this.vertexTL.Position.X = x;
   this.vertexTL.Position.Y = y;
   this.vertexTL.Position.Z = this.Depth;
   this.vertexTL.Color = color;
   this.vertexTL.TextureCoordinate.X = texCoordTL.X;
   this.vertexTL.TextureCoordinate.Y = texCoordTL.Y;
   this.vertexTR.Position.X = x + w;
   this.vertexTR.Position.Y = y;
   this.vertexTR.Position.Z = this.Depth;
   this.vertexTR.Color = color;
   this.vertexTR.TextureCoordinate.X = texCoordBR.X;
   this.vertexTR.TextureCoordinate.Y = texCoordTL.Y;
   this.vertexBL.Position.X = x;
   this.vertexBL.Position.Y = y + h;
   this.vertexBL.Position.Z = this.Depth;
   this.vertexBL.Color = color;
   this.vertexBL.TextureCoordinate.X = texCoordTL.X;
   this.vertexBL.TextureCoordinate.Y = texCoordBR.Y;
   this.vertexBR.Position.X = x + w;
   this.vertexBR.Position.Y = y + h;
   this.vertexBR.Position.Z = this.Depth;
   this.vertexBR.Color = color;
   this.vertexBR.TextureCoordinate.X = texCoordBR.X;
   this.vertexBR.TextureCoordinate.Y = texCoordBR.Y;
 }
開發者ID:Zeludon,項目名稱:FEZ,代碼行數:27,代碼來源:SpriteBatchItem.cs

示例3: AmountFaceRightUp

        public Vector2 AmountFaceRightUp(PlayerIndex? controllingPlayer, out PlayerIndex playerIndex)
        {
            Vector2 amountFaceRightUp;
            bool w, a, s, d;
            w = a = s = d = false;
            if (controllingPlayer.HasValue && GamePad.GetState((PlayerIndex)controllingPlayer).IsConnected)
            {
                playerIndex = (PlayerIndex)controllingPlayer; //we have the player set if it's a controller.
                amountFaceRightUp = GamePad.GetState((PlayerIndex)controllingPlayer).ThumbSticks.Left;
            }
            else
            {
                w = IsKeyDown(Keys.W, controllingPlayer, out playerIndex);
                a = IsKeyDown(Keys.A, controllingPlayer, out playerIndex);
                s = IsKeyDown(Keys.S, controllingPlayer, out playerIndex);
                d = IsKeyDown(Keys.D, controllingPlayer, out playerIndex);

                float amountFaceRight = ((d) ? 1.0f : 0.0f) + (((a)) ? -1.0f : 0.0f);
                float amountFaceUp = ((w) ? 1.0f : 0.0f) + (((s)) ? -1.0f : 0.0f);

                amountFaceRightUp = new Vector2(amountFaceRight, amountFaceUp);
            }

            return amountFaceRightUp;
        }
開發者ID:funkjunky,項目名稱:Revenge-of-the-Morito-2-,代碼行數:25,代碼來源:InputState.cs

示例4: Toolbar

 public Toolbar(Texture2D texture, SpriteFont font, Vector2 position)
 {
     _texture = texture;
     _font = font;
     _position = position;
     _textPosition=new Vector2(130,_position.Y+10);
 }
開發者ID:hover024,項目名稱:Virus-Attack,代碼行數:7,代碼來源:Toolbar.cs

示例5: DrawFlagScore

        public void DrawFlagScore(SpriteBatch spriteBatch, GameTime gameTime, float stoppingHeight)
        {
            scoreOrigin = ScoreFont.MeasureString(scoreText) / GameValues.ScoreSpriteScoreOriginOffset;

            spriteBatch.DrawString(ScoreFont, scoreText, new Vector2(Position.X, Position.Y - GameValues.ScoreSpriteDrawFlagScoreYOffset), Color.White, 0, scoreOrigin, 0.4f, SpriteEffects.None, 0f);

            if (Position.Y > stoppingHeight)
            {
                Position = new Vector2(Position.X, Position.Y - GameValues.ScoreSpriteDrawFlagScoreDropOffet);
            }
            else if (Position.Y <= stoppingHeight)
            {
                //Position.Y = stoppingHeight;
                Position = new Vector2(Position.X, stoppingHeight);
                if (scoreBuffer <= 0)
                {
                    scoreBuffer = GameValues.ScoreSpriteScoreBuffer;
                    ScoringOn = !ScoringOn;
                }
                else
                {
                    scoreBuffer--;
                }
            }
        }
開發者ID:BoltThrower,項目名稱:Super-Mario-World-1-1,代碼行數:25,代碼來源:ScoreSprite.cs

示例6: Draw

        public void Draw(SpriteBatch spriteBatch, Vector2 location, ObjectState state)
        {
            this.SpriteWidth = this.Texture.Width / this.Columns;
            this.SpriteHeight = this.Texture.Height / this.Rows;

            if (state == ObjectState.Moving)
            {
                int row = (int)((float)this.currentFrame / this.Columns);
                int column = this.currentFrame % this.Columns;

                var sourceRectangle = new Rectangle(this.SpriteWidth * column, this.SpriteHeight * row, this.SpriteWidth, this.SpriteHeight);
                var destinationRectangle = new Rectangle((int)location.X, (int)location.Y, this.SpriteWidth, this.SpriteHeight);

                spriteBatch.Begin();
                spriteBatch.Draw(this.Texture, destinationRectangle, sourceRectangle, Color.White, this.Rotation, new Vector2(0, 0), this.Effects, 0f);
                spriteBatch.End();
            }
            else
            {
                var sourceRectangle = new Rectangle(0, 0, this.SpriteWidth, this.SpriteHeight);
                var destinationRectangle = new Rectangle((int)location.X, (int)location.Y, this.SpriteWidth, this.SpriteHeight);

                spriteBatch.Begin();
                spriteBatch.Draw(this.Texture, destinationRectangle, sourceRectangle, Color.White, this.Rotation, new Vector2(0, 0), this.Effects, 0f);
                spriteBatch.End();
            }
        }
開發者ID:TeamCherryBomb,項目名稱:CherryQuest,代碼行數:27,代碼來源:DrawableGameObject.cs

示例7: Bullet

 public Bullet(SchmupGame game, Vector2 position, Vector2 velocity, string bulletTexturePath)
     : base(game)
 {
     Position = position;
     Velocity = velocity;
     this.bulletTexturePath = bulletTexturePath;
 }
開發者ID:isaque,項目名稱:Schmup,代碼行數:7,代碼來源:Bullet.cs

示例8: Position2DComponent

 public Position2DComponent(uint id)
     : base(id)
 {
     Position = Vector2.Zero;
     Rotation = 0.0f;
     Origin = Vector2.Zero;
 }
開發者ID:Norskan,項目名稱:Playground,代碼行數:7,代碼來源:Position2DComponent.cs

示例9: WorldMapView

 public WorldMapView(SpriteBatch sb)
 {
     spriteBatch = sb;
     instructionPos = new Vector2(20, 21);
     instructionOffset = new Vector2(0, 40);
     tutorial = "Press I to open tutorial";
 }
開發者ID:calebperkins,項目名稱:Ensembler,代碼行數:7,代碼來源:WorldMapView.cs

示例10: FloppyDisc

        public FloppyDisc(Game game, SpriteBatch spriteBatch, Texture2D texture, Texture2D overlayTexture, Color color, Color overlayColor,
			Vector2 position, float rotation , float scale, float layerDepth, int points)
            : base(game, spriteBatch, texture, color, position, rotation, scale, layerDepth, points)
        {
            this.overlayTexture = overlayTexture;
            this.overlayColor = overlayColor;
        }
開發者ID:UnaviaMedia,項目名稱:CaptainCPA,代碼行數:7,代碼來源:FloppyDisc.cs

示例11: Pyramid

        public Pyramid(World world, Vector2 position, int count, float density)
        {
            Vertices rect = PolygonTools.CreateRectangle(0.5f, 0.5f);
            PolygonShape shape = new PolygonShape(rect, density);

            Vector2 rowStart = position;
            rowStart.Y -= 0.5f + count * 1.1f;

            Vector2 deltaRow = new Vector2(-0.625f, 1.1f);
            const float spacing = 1.25f;

            // Physics
            _boxes = new List<Body>();

            for (int i = 0; i < count; i++)
            {
                Vector2 pos = rowStart;

                for (int j = 0; j < i + 1; j++)
                {
                    Body body = BodyFactory.CreateBody(world);
                    body.BodyType = BodyType.Dynamic;
                    body.Position = pos;
                    body.CreateFixture(shape);
                    _boxes.Add(body);

                    pos.X += spacing;
                }
                rowStart += deltaRow;
            }

            //GFX
            _box = new Sprite(ContentWrapper.PolygonTexture(rect, "Square", ContentWrapper.Blue, ContentWrapper.Gold, ContentWrapper.Black, 1f));
        }
開發者ID:tinco,項目名稱:Farseer-Physics,代碼行數:34,代碼來源:Pyramid.cs

示例12: CreateChain

        /// <summary>
        /// Creates a chain.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="linkWidth">The width.</param>
        /// <param name="linkHeight">The height.</param>
        /// <param name="fixStart">if set to <c>true</c> [fix start].</param>
        /// <param name="fixEnd">if set to <c>true</c> [fix end].</param>
        /// <param name="numberOfLinks">The number of links.</param>
        /// <param name="linkDensity">The link density.</param>
        /// <returns></returns>
        public static Path CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight, bool fixStart, bool fixEnd, int numberOfLinks, float linkDensity)
        {
            // Chain start / end
            Path path = new Path();
            path.Add(start);
            path.Add(end);

            // A single chainlink
            PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(linkWidth, linkHeight));

            // Use PathManager to create all the chainlinks based on the chainlink created before.
            List<Body> chainLinks = PathManager.EvenlyDistibuteShapesAlongPath(world, path, shape, BodyType.Dynamic, numberOfLinks, linkDensity);

            if (fixStart)
            {
                // Fix the first chainlink to the world
                JointFactory.CreateFixedRevoluteJoint(world, chainLinks[0], new Vector2(0, -(linkHeight / 2)), chainLinks[0].Position);
            }

            if (fixEnd)
            {
                // Fix the last chainlink to the world
                JointFactory.CreateFixedRevoluteJoint(world, chainLinks[chainLinks.Count - 1], new Vector2(0, (linkHeight / 2)), chainLinks[chainLinks.Count - 1].Position);
            }

            // Attach all the chainlinks together with a revolute joint
            PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight), new Vector2(0, linkHeight),
                                                      false, false);

            return (path);
        }
開發者ID:scastle,項目名稱:Solitude,代碼行數:44,代碼來源:LinkFactory.cs

示例13: PyramidTest

        private PyramidTest()
        {
            //Create ground
            FixtureFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            Vertices box = PolygonTools.CreateRectangle(0.5f, 0.5f);
            PolygonShape shape = new PolygonShape(box, 5);

            Vector2 x = new Vector2(-7.0f, 0.75f);
            Vector2 deltaX = new Vector2(0.5625f, 1.25f);
            Vector2 deltaY = new Vector2(1.125f, 0.0f);

            for (int i = 0; i < Count; ++i)
            {
                Vector2 y = x;

                for (int j = i; j < Count; ++j)
                {
                    Body body = BodyFactory.CreateBody(World);
                    body.BodyType = BodyType.Dynamic;
                    body.Position = y;
                    body.CreateFixture(shape);

                    y += deltaY;
                }

                x += deltaX;
            }
        }
開發者ID:danielselnick,項目名稱:Geometric-Replication,代碼行數:29,代碼來源:PyramidTest.cs

示例14: Reset

 // Reset
 public void Reset()
 {
     Offset = new Vector2();
     Scale = new Vector2( 1.0f );
     Rotation = new Vector3();
     TransformMatrix = Matrix.Identity;
 }
開發者ID:JacobNorlin,項目名稱:project-duck,代碼行數:8,代碼來源:CameraSettings.cs

示例15: Draw

        public override void Draw(GameTime gameTime)
        {
            if (_inputService.IsDown(Keys.F1) || _inputService.IsDown(Buttons.Start, PlayerIndex.One))
              {
            // F1 is pressed:

            // Clear screen.
            GraphicsDevice.Clear(Color.White);

            // Draw help text.
            float left = GraphicsDevice.Viewport.TitleSafeArea.Left;
            float top = GraphicsDevice.Viewport.TitleSafeArea.Top;
            Vector2 position = new Vector2(left, top);

            _spriteBatch.Begin();
            _spriteBatch.DrawString(_spriteFont, Text, position, Color.Black);
            _spriteBatch.End();
              }
              else
              {
            // F1 is not pressed:

            // Draw a help hint at the bottom of the screen.
            float left = GraphicsDevice.Viewport.TitleSafeArea.Left;
            float bottom = GraphicsDevice.Viewport.TitleSafeArea.Bottom - 30;
            Vector2 position = new Vector2(left, bottom);
            const string text = "Press <F1> or <Start> to display Help";

            _spriteBatch.Begin();
            _spriteBatch.DrawStringOutlined(_spriteFont, text, position, Color.Black, Color.White);
            _spriteBatch.End();
              }

              base.Draw(gameTime);
        }
開發者ID:HATtrick-games,項目名稱:ICT309,代碼行數:35,代碼來源:Help.cs


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