/// <summary> /// Sets the given Sprite one pixel off the closest side of the given Rectangle /// </summary> /// <param name="sprite"></param> /// <param name="rect"></param> /// <returns>True if the sprite's position changed, false otherwise</returns> public static bool setSpriteOutsideRectangle(Sprite sprite, Rectangle rect) { if (sprite.getY() + sprite.getHeight() < rect.Y && sprite.getY() != rect.Y - sprite.getHeight()) { sprite.setY(rect.Y - sprite.getHeight()); return true; } else if (sprite.getY() > rect.Y + rect.Height && sprite.getY() != rect.Y + rect.Height) { sprite.setY(rect.Y + rect.Height); return true; } if (sprite.getX() + sprite.getWidth() < rect.X && sprite.getX() != rect.X - sprite.getWidth()) { sprite.setX(rect.X - sprite.getWidth()); return true; } else if (sprite.getX() > rect.X + rect.Width && sprite.getX() != rect.X + rect.Width) { sprite.setX(rect.X + rect.Width); return true; } return false; }
public static MapObject collisionWithObjectAtRelative(Sprite p_sprite, Point p_offset) { return collisionWithObjectAtRelative(p_sprite, p_offset, "Solid"); }