/** * Snaps a coordinate against the bounds of the world so that it may not pass out of the visible * area of the world. * * @param worldX An x-coordinate in world units. * @return An x-coordinate that is guaranteed not to expose the edges of the world. */ public float snapFocalPointToWorldBoundsX(float worldX) { float focalPositionX = worldX; final float width = sSystemRegistry.contextParameters.gameWidth; final LevelSystem level = sSystemRegistry.levelSystem; if (level != null) { final float worldPixelWidth = Math.max(level.getLevelWidth(), width); final float rightEdge = focalPositionX + (width / 2.0f); final float leftEdge = focalPositionX - (width / 2.0f); if (rightEdge > worldPixelWidth) { focalPositionX = worldPixelWidth - (width / 2.0f); } else if (leftEdge < 0) { focalPositionX = width / 2.0f; } } return focalPositionX; }