本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle.getCenter方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.getCenter方法的具体用法?C# Rectangle.getCenter怎么用?C# Rectangle.getCenter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Rectangle
的用法示例。
在下文中一共展示了Rectangle.getCenter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: populateCollidingTiles
/// <summary>
/// gets a list of all the tiles intersecting bounds. The returned list is ordered for collision detection based on the
/// direction passed in so they can be processed in order.
/// </summary>
/// <returns>The colliding tiles.</returns>
/// <param name="bounds">Bounds.</param>
/// <param name="direction">Direction.</param>
void populateCollidingTiles( Rectangle bounds, Edge direction )
{
_collidingTiles.Clear();
var isHorizontal = direction.isHorizontal();
var primaryAxis = isHorizontal ? Axis.X : Axis.Y;
var oppositeAxis = primaryAxis == Axis.X ? Axis.Y : Axis.X;
var oppositeDirection = direction.oppositeEdge();
var firstPrimary = worldToTilePosition( bounds.getSide( oppositeDirection ), primaryAxis );
var lastPrimary = worldToTilePosition( bounds.getSide( direction ), primaryAxis );
var primaryIncr = direction.isMax() ? 1 : -1;
var min = worldToTilePosition( isHorizontal ? bounds.Top : bounds.Left, oppositeAxis );
var mid = worldToTilePosition( isHorizontal ? bounds.getCenter().Y : bounds.getCenter().X, oppositeAxis );
var max = worldToTilePosition( isHorizontal ? bounds.Bottom : bounds.Right, oppositeAxis );
var isPositive = mid - min < max - mid;
var secondaryIncr = isPositive ? 1 : -1;
var firstSecondary = isPositive ? min : max;
var lastSecondary = !isPositive ? min : max;
for( var primary = firstPrimary; primary != lastPrimary + primaryIncr; primary += primaryIncr )
{
for( var secondary = firstSecondary; secondary != lastSecondary + secondaryIncr; secondary += secondaryIncr )
{
var col = isHorizontal ? primary : secondary;
var row = !isHorizontal ? primary : secondary;
_collidingTiles.Add( collisionLayer.getTile( col, row ) );
#if DEBUG_MOVER
if( direction.isHorizontal() )
{
var pos = tiledMap.tileToWorldPosition( new Point( col, row ) );
_debugTiles.Add( new Rectangle( (int)pos.X, (int)pos.Y, 16, 16 ) );
}
#endif
}
}
}
示例2: populateCollidingTiles
/// <summary>
/// gets a list of all the tiles intersecting bounds. The returned list is ordered for collision detection based on the
/// direction passed in so they can be processed in order.
/// </summary>
/// <returns>The colliding tiles.</returns>
/// <param name="bounds">Bounds.</param>
/// <param name="direction">Direction.</param>
void populateCollidingTiles( Rectangle bounds, Edge direction )
{
_collidingTiles.Clear();
var isHorizontal = direction.isHorizontal();
var primaryAxis = isHorizontal ? Axis.X : Axis.Y;
var oppositeAxis = primaryAxis == Axis.X ? Axis.Y : Axis.X;
// if we are going up or left we subtract 1 from our opposite edge so that it doesnt get the column/row of tiles when we are against them
var oppositeDirection = direction.oppositeEdge();
var minSidePad = direction.isMin() ? -1 : 0;
var firstPrimary = worldToTilePosition( bounds.getSide( oppositeDirection ) + minSidePad, primaryAxis );
var lastPrimary = worldToTilePosition( bounds.getSide( direction ), primaryAxis );
var primaryIncr = direction.isMax() ? 1 : -1;
var min = worldToTilePosition( isHorizontal ? bounds.Top : bounds.Left, oppositeAxis );
var mid = worldToTilePosition( isHorizontal ? bounds.getCenter().Y : bounds.getCenter().X, oppositeAxis );
// same as above here. we subtract 1 to not grab an extra column/row of tiles which will mess up collisions
var max = worldToTilePosition( isHorizontal ? bounds.Bottom - 1 : bounds.Right - 1, oppositeAxis );
var isPositive = mid - min < max - mid;
var secondaryIncr = isPositive ? 1 : -1;
var firstSecondary = isPositive ? min : max;
var lastSecondary = !isPositive ? min : max;
for( var primary = firstPrimary; primary != lastPrimary + primaryIncr; primary += primaryIncr )
{
for( var secondary = firstSecondary; secondary != lastSecondary + secondaryIncr; secondary += secondaryIncr )
{
var col = isHorizontal ? primary : secondary;
var row = !isHorizontal ? primary : secondary;
_collidingTiles.Add( _collisionLayer.getTile( col, row ) );
}
}
}