本文整理汇总了C#中SFML.Graphics.Vector2类的典型用法代码示例。如果您正苦于以下问题:C# Vector2类的具体用法?C# Vector2怎么用?C# Vector2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Vector2类属于SFML.Graphics命名空间,在下文中一共展示了Vector2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveManyTransBox
/// <summary>
/// Initializes a new instance of the <see cref="MoveManyTransBox"/> class.
/// </summary>
/// <param name="owner">The <see cref="TransBoxManager"/>.</param>
/// <param name="spatials">The <see cref="ISpatial"/>s.</param>
/// <param name="position">The position.</param>
/// <param name="camera">The camera.</param>
public MoveManyTransBox(TransBoxManager owner, IEnumerable<ISpatial> spatials, Vector2 position, ICamera2D camera)
{
_owner = owner;
_camera = camera;
_position = position;
_spatials = spatials.ToImmutable();
}
示例2: Contains
/// <summary>
/// Checks if the <see cref="ISpatial"/> contains a point.
/// </summary>
/// <param name="spatial">The spatial.</param>
/// <param name="p">Point to check if the <paramref name="spatial"/> contains.</param>
/// <returns>True if the <paramref name="spatial"/> contains <paramref name="p"/>; otherwise false.</returns>
public static bool Contains(this ISpatial spatial, Vector2 p)
{
var min = spatial.Position;
var max = spatial.Max;
return (min.X <= p.X && max.X >= p.X && min.Y <= p.Y && max.Y >= p.Y);
}
示例3: MTD
/// <summary>
/// Finds the Minimal Translational Distance between two <see cref="ISpatial"/>s.
/// </summary>
/// <param name="srcMin">Top-left of the source (dynamic) <see cref="ISpatial"/> that will be the one moving.</param>
/// <param name="srcMax">Bottom-right of the source (dynamic) <see cref="ISpatial"/> that will be the one moving.</param>
/// <param name="tarMin">Top-left of the target (static) <see cref="ISpatial"/> that will not move.</param>
/// <param name="tarMax">Bottom-right of the target (static) <see cref="ISpatial"/> that will not move.</param>
/// <returns>The MTD for the source to no longer intersect the target.</returns>
public static Vector2 MTD(Vector2 srcMin, Vector2 srcMax, Vector2 tarMin, Vector2 tarMax)
{
// Down
float mtd = srcMax.Y - tarMin.Y;
BoxSide side = BoxSide.Bottom;
// Left
float diff = srcMax.X - tarMin.X;
if (diff < mtd)
{
mtd = diff;
side = BoxSide.Left;
}
// Right
diff = tarMax.X - srcMin.X;
if (diff < mtd)
{
mtd = diff;
side = BoxSide.Right;
}
// Up
diff = tarMax.Y - srcMin.Y;
if (diff < mtd)
{
mtd = diff;
side = BoxSide.Top;
}
if (mtd < 0.0f)
return Vector2.Zero;
return CreateMTDVector(side, mtd + 1);
}
示例4: ContainsPoint
/// <summary>
/// Checks if this <see cref="ITransBox"/> contains the given world point.
/// </summary>
/// <param name="worldPos">The world point.</param>
/// <returns>True if this <see cref="ITransBox"/> contains the <paramref name="worldPos"/>; otherwise false.</returns>
public bool ContainsPoint(Vector2 worldPos)
{
var w = worldPos;
var lo = Position;
var hi = Max;
return (lo.X <= w.X) && (lo.Y <= w.Y) && (hi.X >= w.X) && (hi.Y >= w.Y);
}
示例5: Align
Vector2 Align(Vector2 v)
{
if (_owner == null || _owner.GridAligner == null)
return v;
return _owner.GridAligner.Align(v);
}
示例6: ChatForm
/// <summary>
/// Initializes a new instance of the <see cref="ChatForm"/> class.
/// </summary>
/// <param name="parent">The parent.</param>
/// <param name="pos">The pos.</param>
public ChatForm(Control parent, Vector2 pos) : base(parent, pos, new Vector2(300, 150))
{
// Create the input and output TextBoxes
_input = new TextBox(this, Vector2.Zero, new Vector2(32, 32))
{
IsMultiLine = false,
IsEnabled = true,
Font = GameScreenHelper.DefaultChatFont,
MaxInputTextLength = GameData.MaxClientSayLength,
BorderColor = new Color(255, 255, 255, 100)
};
_output = new TextBox(this, Vector2.Zero, new Vector2(32, 32))
{
IsMultiLine = true,
IsEnabled = false,
Font = GameScreenHelper.DefaultChatFont,
BorderColor = new Color(255, 255, 255, 100)
};
_input.KeyPressed -= Input_KeyPressed;
_input.KeyPressed += Input_KeyPressed;
// Force the initial repositioning
RepositionTextBoxes();
}
示例7: Draw
/// <summary>
/// Draws the <see cref="SkeletonBodyItem"/>.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
/// <param name="position">Position to draw at.</param>
/// <param name="scale">Amount to scale the Grh in percent (1.0f for no scaling).</param>
/// <param name="color">The color.</param>
/// <param name="effect">SpriteEffects to use when drawing.</param>
internal void Draw(ISpriteBatch sb, Vector2 position, float scale, Color color, SpriteEffects effect)
{
// Validate
if (Source == null)
return;
// Find the effect
Vector2 m;
switch (effect)
{
case SpriteEffects.FlipHorizontally:
m = new Vector2(-1, 1);
break;
case SpriteEffects.FlipVertically:
m = new Vector2(1, -1);
break;
default:
m = new Vector2(1, 1);
break;
}
// Calculate the angle
float angle;
if (Dest == null)
angle = 0.0f;
else
angle = SkeletonNode.GetAngle(Source.Position * m, Dest.Position * m) - MathHelper.PiOver2;
// Draw
var v = Source.Position + ItemInfo.Offset;
Grh.Draw(sb, (v * m) + position, color, effect, angle, ItemInfo.Origin, scale);
}
示例8: Play
/// <summary>
/// Plays a sound.
/// </summary>
/// <param name="soundManager">The sound manager.</param>
/// <param name="name">The name of the sound to play.</param>
/// <param name="source">The source of the sound.</param>
/// <returns>
/// True if the sound was successfully played; otherwise false.
/// </returns>
public static bool Play(this ISoundManager soundManager, string name, Vector2 source)
{
var info = soundManager.GetSoundInfo(name);
if (info == null)
return false;
return soundManager.Play(info.ID, source);
}
示例9: SkeletonBodyItemInfo
/// <summary>
/// Initializes a new instance of the <see cref="SkeletonBodyItemInfo"/> class.
/// </summary>
/// <param name="grhIndex">The <see cref="GrhIndex"/> for the sprite to draw for the body item.</param>
/// <param name="sourceName">Name of the source node.</param>
/// <param name="destName">Name of the destination node (String.Empty for no destination).</param>
/// <param name="offset">Grh drawing offset.</param>
/// <param name="origin">Grh drawing origin.</param>
public SkeletonBodyItemInfo(GrhIndex grhIndex, string sourceName, string destName, Vector2 offset, Vector2 origin)
{
GrhIndex = grhIndex;
_sourceName = sourceName;
_destName = destName;
Offset = offset;
Origin = origin;
}
示例10: Toolbar
/// <summary>
/// Initializes a new instance of the <see cref="Toolbar"/> class.
/// </summary>
/// <param name="parent">The parent.</param>
/// <param name="pos">The pos.</param>
public Toolbar(Control parent, Vector2 pos) : base(parent, pos, Vector2.One)
{
ResizeToChildren = true;
ResizeToChildrenPadding = _padding;
_items = CreateToolbarItems();
Position = pos;
}
示例11: CreateEntities
static IEnumerable<Entity> CreateEntities(int amount, Vector2 minPos, Vector2 maxPos)
{
var ret = new Entity[amount];
for (var i = 0; i < amount; i++)
{
ret[i] = new TestEntity { Position = RandomHelper.NextVector2(minPos, maxPos) };
}
return ret;
}
示例12: Draw
/// <summary>
/// Draws a rectangle.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
/// <param name="position">Top-left corner position.</param>
/// <param name="size">The size of the rectangle.</param>
/// <param name="color">Color of the rectangle.</param>
public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color)
{
var drawRect = _drawRectBorder;
drawRect.Size = size;
drawRect.Position = position;
drawRect.FillColor = color;
sb.Draw(drawRect);
}
示例13: ThralledNPC
public ThralledNPC(World parent, CharacterTemplate template, Map map, Vector2 position)
: base(parent, template, map, position)
{
// This NPC should never respawn. Once it's dead, that should be it!
RespawnMapID = null;
RespawnPosition = Vector2.Zero;
if (log.IsDebugEnabled)
log.DebugFormat("Created ThralledNPC `{0}` on map `{1}` at `{2}` with template `{3}`.", this, Map, Position,
template);
}
示例14: GetObjUnderCursor
/// <summary>
/// Gets the selectable object currently under the cursor.
/// </summary>
/// <param name="map">The <see cref="EditorMap"/>.</param>
/// <param name="worldPos">The world position.</param>
/// <returns>The selectable object currently under the cursor, or null if none.</returns>
protected override object GetObjUnderCursor(EditorMap map, Vector2 worldPos)
{
var closestLight = map.Lights.MinElementOrDefault(x => worldPos.QuickDistance(x.Center));
if (closestLight == null)
return null;
if (worldPos.QuickDistance(closestLight.Center) > 10)
return null;
return closestLight;
}
示例15: DrawStringShaded
/// <summary>
/// Draws a string with shading.
/// </summary>
/// <param name="spriteBatch"><see cref="ISpriteBatch"/> to use to draw.</param>
/// <param name="font"><see cref="Font"/> to draw the string with.</param>
/// <param name="text">The string to draw.</param>
/// <param name="position">The position of the top-left corner of the string to draw.</param>
/// <param name="fontColor">The font color.</param>
/// <param name="borderColor">The shading color.</param>
public static void DrawStringShaded(this ISpriteBatch spriteBatch, Font font, string text, Vector2 position,
Color fontColor, Color borderColor)
{
position = position.Round();
spriteBatch.DrawString(font, text, position - new Vector2(0, 1), borderColor);
spriteBatch.DrawString(font, text, position - new Vector2(1, 0), borderColor);
spriteBatch.DrawString(font, text, position + new Vector2(0, 1), borderColor);
spriteBatch.DrawString(font, text, position + new Vector2(1, 0), borderColor);
spriteBatch.DrawString(font, text, position, fontColor);
}