本文整理汇总了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);
}
示例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;
}
示例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;
}
示例4: Toolbar
public Toolbar(Texture2D texture, SpriteFont font, Vector2 position)
{
_texture = texture;
_font = font;
_position = position;
_textPosition=new Vector2(130,_position.Y+10);
}
示例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--;
}
}
}
示例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();
}
}
示例7: Bullet
public Bullet(SchmupGame game, Vector2 position, Vector2 velocity, string bulletTexturePath)
: base(game)
{
Position = position;
Velocity = velocity;
this.bulletTexturePath = bulletTexturePath;
}
示例8: Position2DComponent
public Position2DComponent(uint id)
: base(id)
{
Position = Vector2.Zero;
Rotation = 0.0f;
Origin = Vector2.Zero;
}
示例9: WorldMapView
public WorldMapView(SpriteBatch sb)
{
spriteBatch = sb;
instructionPos = new Vector2(20, 21);
instructionOffset = new Vector2(0, 40);
tutorial = "Press I to open tutorial";
}
示例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;
}
示例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));
}
示例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);
}
示例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;
}
}
示例14: Reset
// Reset
public void Reset()
{
Offset = new Vector2();
Scale = new Vector2( 1.0f );
Rotation = new Vector3();
TransformMatrix = Matrix.Identity;
}
示例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);
}