本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Contains方法的具体用法?C# Rectangle.Contains怎么用?C# Rectangle.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Rectangle
的用法示例。
在下文中一共展示了Rectangle.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleEvent
public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
{
var mousePressEvent = @event as MousePressEvent;
if (mousePressEvent != null)
{
if (!layout.Contains(mousePressEvent.MouseState.X, mousePressEvent.MouseState.Y))
{
return false;
}
State = LinkState.Clicked;
Click?.Invoke(this, new EventArgs());
return true;
}
var mouseReleaseEvent = @event as MouseReleaseEvent;
if (mouseReleaseEvent != null)
{
if (!layout.Contains(mouseReleaseEvent.MouseState.X, mouseReleaseEvent.MouseState.Y))
{
return false;
}
State = LinkState.None;
}
return false;
}
示例2: ContainsPoint
public void ContainsPoint()
{
Rectangle rectangle = new Rectangle(0,0,64,64);
var p1 = new Point(-1, -1);
var p2 = new Point(0, 0);
var p3 = new Point(32, 32);
var p4 = new Point(63, 63);
var p5 = new Point(64, 64);
bool result;
rectangle.Contains(ref p1, out result);
Assert.AreEqual(false, result);
rectangle.Contains(ref p2, out result);
Assert.AreEqual(true, result);
rectangle.Contains(ref p3, out result);
Assert.AreEqual(true, result);
rectangle.Contains(ref p4, out result);
Assert.AreEqual(true, result);
rectangle.Contains(ref p5, out result);
Assert.AreEqual(false, result);
Assert.AreEqual(false, rectangle.Contains(p1));
Assert.AreEqual(true, rectangle.Contains(p2));
Assert.AreEqual(true, rectangle.Contains(p3));
Assert.AreEqual(true, rectangle.Contains(p4));
Assert.AreEqual(false, rectangle.Contains(p5));
}
示例3: LineIntersectsRect
public static bool LineIntersectsRect(Point p1, Point p2, Rectangle r)
{
return LineIntersectsLine(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)) ||
LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)) ||
(r.Contains(p1) && r.Contains(p2));
}
示例4: LineIntersectsRect
public bool LineIntersectsRect(Vector2 p1, Vector2 p2, Rectangle r)
{
return LineIntersectsLine(p1, p2, new Vector2(r.X, r.Y), new Vector2(r.X + r.Width, r.Y)) ||
LineIntersectsLine(p1, p2, new Vector2(r.X + r.Width, r.Y), new Vector2(r.X + r.Width, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Vector2(r.X + r.Width, r.Y + r.Height), new Vector2(r.X, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Vector2(r.X, r.Y + r.Height), new Vector2(r.X, r.Y)) ||
(r.Contains(p1) && r.Contains(p2));
}
示例5: LineIntersectsRect
//adapted from http://stackoverflow.com/questions/5514366/how-to-know-if-a-line-intersects-a-rectangle
public static bool LineIntersectsRect(Vector2 p1, Vector2 p2, Rectangle r)
{
return LineIntersectsLine(p1, p2, new Vector2(r.X, r.Y), new Vector2(r.X + r.Width, r.Y)) ||
LineIntersectsLine(p1, p2, new Vector2(r.X + r.Width, r.Y), new Vector2(r.X + r.Width, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Vector2(r.X + r.Width, r.Y + r.Height), new Vector2(r.X, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Vector2(r.X, r.Y + r.Height), new Vector2(r.X, r.Y)) ||
(r.Contains(new Point((int)p1.X, (int)p1.Y)) && r.Contains(new Point((int)p2.X, (int)p2.Y)));
}
示例6: HandleEvent
public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
{
var mousePressEvent = @event as MousePressEvent;
var touchPressEvent = @event as TouchPressEvent;
if (mousePressEvent != null && mousePressEvent.Button == MouseButton.Left)
{
if (layout.Contains(mousePressEvent.MouseState.X, mousePressEvent.MouseState.Y))
{
this.Focus();
return true;
}
}
if (touchPressEvent != null)
{
if (layout.Contains((int)touchPressEvent.X, (int)touchPressEvent.Y))
{
this.Focus();
#if PLATFORM_ANDROID
var manager = (InputMethodManager)Game.Activity.GetSystemService(Context.InputMethodService);
manager.ShowSoftInput(((Microsoft.Xna.Framework.AndroidGameWindow)context.Game.Window).GameViewAsView, ShowFlags.Forced);
#endif
return true;
}
else
{
#if PLATFORM_ANDROID
var manager = (InputMethodManager)Game.Activity.GetSystemService(Context.InputMethodService);
manager.HideSoftInputFromWindow(((Microsoft.Xna.Framework.AndroidGameWindow)context.Game.Window).GameViewAsView.WindowToken, HideSoftInputFlags.None);
#endif
}
}
var keyEvent = @event as KeyboardEvent;
if (keyEvent != null)
{
var keyboard = keyEvent.KeyboardState;
if (Focused)
{
_keyboardReader.Process(keyboard, context.GameTime, _textBuilder);
if (_textBuilder.ToString() != _previousValue)
{
TextChanged?.Invoke(this, new EventArgs());
}
_previousValue = _textBuilder.ToString();
return true;
}
}
return false;
}
示例7: LineIntersectsRect
public static bool LineIntersectsRect(Vector2 pp1, Vector2 pp2, Rectangle r)
{
Point p1 = new Point((int)pp1.X, (int)pp1.Y);
Point p2 = new Point((int)pp2.X, (int)pp2.Y);
return LineIntersectsLine(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)) ||
LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)) ||
LineIntersectsLine(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)) ||
(r.Contains(p1) && r.Contains(p2));
}
示例8: setCameraBounds
public void setCameraBounds(Vector2 cameraXBounds, Vector2 cameraYBounds)
{
cameraRect = new Rectangle(-1 * (int)cameraXBounds.X, -1 * (int)cameraYBounds.X,
-1 * ((int)cameraXBounds.Y - (int)cameraXBounds.X), -1 * ((int)cameraYBounds.Y - (int)cameraYBounds.X));
Console.WriteLine(cameraRect + " CAMERARECT");
Console.WriteLine(cameraRect.Contains(new Vector2(145, 320)));
}
示例9: Update
public void Update(bool isMuteButton, GameTime gameTime)
{
MouseState mouse = Mouse.GetState();
rectangle = new Rectangle((int)(position.X), (int)(position.Y), (int)(Size.X), (int)(Size.Y));
Point mousePos = new Point(mouse.X, mouse.Y);
if ((rectangle.Contains(mousePos) && mouse.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released)|| clickDetected)
{
clickDetected = true;
if (normalTimer.CallTimer(gameTime) && !isMuteButton)
{
IsClicked = true;
clickDetected = false;
}
else
{
if (isMuteButton && muteTimer.CallTimer(gameTime))
{
IsClicked = true;
clickDetected = false;
}
}
}
else IsClicked = false;
oldMouseState = mouse;
}
示例10: ContainsPoint
public bool ContainsPoint(Point _point)
{
Rectangle r = new Rectangle((int)position.X,(int)position.Y,sideLength,sideLength);
if(r.Contains(_point))
return true;
return false;
}
示例11: AddToButtonGroup
/// <summary>
/// Checks to see if a button group's rectangle is big enough to contain the button and if not expands it
/// </summary>
/// <param name="lButtonGroupArea">The current rectangle of the button group</param>
public void AddToButtonGroup(ref Rectangle lButtonGroupArea)
{
if (!lButtonGroupArea.Contains(mLocation))
{
{
int xDist = mLocation.X - lButtonGroupArea.X;
if (xDist < 0)
{
lButtonGroupArea.X = mLocation.X;
lButtonGroupArea.Width -= xDist;
}
xDist = mLocation.Right - lButtonGroupArea.Right;
if (xDist > 0)
{
lButtonGroupArea.Width += xDist;
}
}
{
int yDist = mLocation.Y - lButtonGroupArea.Y;
if (yDist < 0)
{
lButtonGroupArea.Y = mLocation.Y;
lButtonGroupArea.Height -= yDist;
}
yDist = mLocation.Bottom - lButtonGroupArea.Bottom;
if (yDist > 0)
{
lButtonGroupArea.Height += yDist;
}
}
}
}
示例12: CollisionWithMouse
/// <summary>
/// This is a collision detection algorithom that tracks collisions between
/// the mouse and any arbitrary 2D sprite
/// </summary>
/// <param name="rect"> Rectangle the sprite is in.</param>
/// <param name="state">The current mouse state</param>
/// <returns>bool stating if a collision occured</returns>
public static bool CollisionWithMouse(Rectangle rect, MouseState state)
{
if (!rect.Contains(state.X, state.Y))
return false;
return true;
}
示例13: IsNewMouseLeftButtonPressed
/// <summary>
/// 鼠标左键是否刚刚按下
/// </summary>
public bool IsNewMouseLeftButtonPressed(Rectangle rect)
{
if (!rect.Contains(CurrentMouseState.X, CurrentMouseState.Y)) return false;
return (LastMouseState.LeftButton == ButtonState.Released)
&& (CurrentMouseState.LeftButton == ButtonState.Pressed);
}
示例14: GetMouseLocationOffset
/// <summary>
/// 得到鼠标位置的变化量
/// </summary>
public Point GetMouseLocationOffset(Rectangle rect)
{
if (!rect.Contains(CurrentMouseState.X, CurrentMouseState.Y)) return new Point();
return new Point(CurrentMouseState.X - LastMouseState.X,
CurrentMouseState.Y - LastMouseState.Y);
}
示例15: CollisionCheck
public static CollisionResponse CollisionCheck(BoundingCircle c, Rectangle r) {
CollisionResponse result = new CollisionResponse();
Vector2 closestPoint = ClosestPointPointRectangle(c.center, r);
float distanceSquared = Vector2.DistanceSquared(closestPoint,c.center);
bool contained = r.Contains(c.center);
if(distanceSquared < c.radius * c.radius || contained){
result.collided = true;
result.normal = c.center - closestPoint;
result.normal.Normalize();
//Special case for a circle with center inside the rectangle
if (contained)
{
result.normal = -result.normal;
result.penetrationDepth = c.radius + (float)Math.Sqrt(distanceSquared);
}
else {
result.penetrationDepth = c.radius - (float)Math.Sqrt(distanceSquared);
}
} else {
result.collided = false;
}
return result;
}