Search Regions and Fixed Locations
Understanding the difference between normal search regions and fixed locations is crucial for efficient pattern matching in Brobot. This guide explains these concepts and how they work together.
Quick Startโ
Define a search region and mark a pattern as fixed in just a few lines:
import io.github.jspinak.brobot.model.element.Region;
import io.github.jspinak.brobot.model.state.StateImage;
// Define where to search (lower left quarter)
Region searchArea = Region.builder()
.withScreenPercentage(0.0, 0.5, 0.5, 0.5)
.build();
// Create pattern with search region
StateImage logo = new StateImage.Builder()
.addPatterns("logo.png")
.setSearchRegionForAllPatterns(searchArea)
.build();
// Mark as fixed - will remember location after first find
logo.getPatterns().forEach(p -> p.setFixed(true));
Result: First search uses the defined region. Subsequent searches go directly to the saved location for near-instant results.
Overviewโ
Brobot uses two complementary concepts for locating visual elements:
- Search Regions: Areas where patterns are searched for
- Fixed Locations: Remembered positions where patterns were previously found
Visual Flow: How Search Regions and Fixed Locations Work Togetherโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Screen โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Search Region (defined) โ โ
โ โ โ โ
โ โ Pattern โ โ
โ โ First Search โ โ
โ โ โโ Search entire region โ โ
โ โ โโ Found at (100, 200) โ โ โ
โ โ โ โ โ