当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle.getCenter方法代码示例

本文整理汇总了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
				}
			}
		}
开发者ID:prime31,项目名称:Nez,代码行数:46,代码来源:TiledMapMover.cs

示例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 ) );
                }
            }
        }
开发者ID:RastaCow,项目名称:Nez,代码行数:41,代码来源:TiledMapMover.cs


注:本文中的Microsoft.Xna.Framework.Rectangle.getCenter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。