本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle.EIntersects方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.EIntersects方法的具体用法?C# Rectangle.EIntersects怎么用?C# Rectangle.EIntersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Rectangle
的用法示例。
在下文中一共展示了Rectangle.EIntersects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: adjustVelocityForRectangleCollision
private void adjustVelocityForRectangleCollision(Entity entity, float deltaT, Rectangle rect, ref Vector2 velocity)
{
Vector2 intersectionAmount;
Vector2 tempPosition = entity.Position + (velocity * deltaT);
if (rect.EIntersects(entity.GetBoundingBoxAt(tempPosition)))
{
tempPosition = entity.Position;
tempPosition.X += velocity.X * deltaT;
if (entity.GetBoundingBoxAt(tempPosition).Intersects(rect, out intersectionAmount))
{
bool positive = velocity.X >= 0;
velocity.X -= intersectionAmount.X / deltaT;
if ((positive && velocity.X < 0) || (!positive && velocity.X > 0))
velocity.X = 0;
}
tempPosition = entity.Position;
tempPosition.Y += velocity.Y * deltaT;
if (entity.GetBoundingBoxAt(tempPosition).Intersects(rect, out intersectionAmount))
{
bool positive = velocity.Y >= 0;
velocity.Y -= intersectionAmount.Y / deltaT;
if ((positive && velocity.Y < 0) || (!positive && velocity.Y > 0))
velocity.Y = 0;
}
}
}
示例2: CollidesWith
public bool CollidesWith(Map map)
{
Rectangle bounds = GetBoundingBox();
Point topLeftTileCoord = new Point(bounds.Left / Map.TileSize, bounds.Top / Map.TileSize);
Point bottomRightTileCoord = new Point(bounds.Right / Map.TileSize, bounds.Bottom / Map.TileSize);
for (int x = topLeftTileCoord.X; x <= bottomRightTileCoord.X; ++x)
{
for (int y = topLeftTileCoord.Y; y <= bottomRightTileCoord.Y; ++y)
{
if (map.CollisionMap[x, y])
{
Rectangle tileRect = new Rectangle(x * Map.TileSize, y * Map.TileSize, Map.TileSize, Map.TileSize);
if (tileRect.EIntersects(bounds))
return true;
}
}
}
return false;
}