/// <summary> /// Gets the bounding box for this entity at the specified GameTime and using the specified /// Tile Width and Height (In Pixels). The result of this method will be returned in pixel units /// and will change from one GameTime instance to another depending on the contents of the entities /// Drawables. If no drawables are found in the entity, then a rectangle with 0 width and 0 height /// will be returned. /// </summary> /// <param name="gameTime">The Current GameTime.</param> /// <returns>An FRectangle object specifying the bounding box of this Entity in Pixels.</returns> public FRectangle GetPxBoundingBox(GameTime gameTime) { HashSet <GameDrawableInstance> drawables = Drawables.GetByState(CurrentDrawableState); if (drawables == null || drawables.Count == 0) { return(new FRectangle(Pos.X, Pos.Y, 0, 0)); } float minX = Int32.MaxValue; float minY = Int32.MaxValue; float maxX = Int32.MinValue; float maxY = Int32.MinValue; foreach (GameDrawableInstance draw in drawables) { Rectangle pxDrawRectangle = draw.GetSourceRectangle(gameTime); Vector2 drawOrigin = draw.Drawable.Origin; float pxWidth = pxDrawRectangle.Width * this.ScaleX; float pxHeight = pxDrawRectangle.Height * this.ScaleY; float pxFrameX = Pos.X + draw.Offset.X + -1 * drawOrigin.X * pxWidth; float pxFrameY = Pos.Y + draw.Offset.Y + -1 * drawOrigin.Y * pxHeight; if (pxFrameX < minX) { minX = pxFrameX; } if (pxFrameY < minY) { minY = pxFrameY; } if (pxFrameX + pxDrawRectangle.Width > maxX) { maxX = pxFrameX + pxWidth; } if (pxFrameY + pxDrawRectangle.Height > maxY) { maxY = pxFrameY + pxHeight; } } return(new FRectangle(minX, minY, maxX - minX, maxY - minY)); }