Difference between revisions of "Bounds"
		
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
		
		
		
		
		
	
| Line 9: | Line 9: | ||
| ! Method or Property !! Purpose | ! Method or Property !! Purpose | ||
| |- | |- | ||
| − | | [[Bounds.x]] || horizontal  | + | | [[Bounds.x]] || horizontal center of the bounds | 
| |- | |- | ||
| − | | [[Bounds.y]] || vertical  | + | | [[Bounds.y]] || vertical center of the bounds | 
| |- | |- | ||
| | [[Bounds.width]] || bounding box width | | [[Bounds.width]] || bounding box width | ||
Latest revision as of 16:31, 8 July 2021
Bounds is a built-in class in the Mini Micro API.  It represents a rectangular bounding box, which can be tested for overlap with other bounding boxes, or for containing a point.  This is often used for collision-checking and hit-testing with Sprites.
Methods and properties used with Bounds objects
Use these methods on Sprite instances, created with new Bounds.
| Method or Property | Purpose | 
|---|---|
| Bounds.x | horizontal center of the bounds | 
| Bounds.y | vertical center of the bounds | 
| Bounds.width | bounding box width | 
| Bounds.height | bounding box height | 
| Bounds.rotation | bounding box rotation (degrees counter-clockwise) | 
| Bounds.corners | returns bounding box corners as a list of [x,y]pairs | 
| Bounds.overlaps(b) | return whether this bounds overlaps bounds b | 
| Bounds.contains(x, y) | return whether the bounds contains the given point | 
Usage Notes
The contains method may be given x and y as two separate arguments; or it may be given an [x, y] list; or it may be given any map containing "x" and "y" keys (such as mouse).
Example
The following example defines a Bounds at the center of the screen, and then enters a loop which draws the bounds yellow when the mouse is over it, and gray when it is not.
b = new Bounds
b.x = 480
b.y = 320
b.width = 200
b.height = 100
b.rotation = 45
while true
	if b.contains(mouse) then
		gfx.drawPoly b.corners, color.yellow
	else
		gfx.drawPoly b.corners, color.gray
	end if
	yield
end while
See also: How to detect a click on a sprite

