GODPAPER | All Packages | All Classes | Index | Frames No Frames |
RectangleUtil

Package | starling.utils
Class | public class RectangleUtil
Inheritance | RectangleUtil Object

A utility class containing methods related to the Rectangle class.

Public Methods

| Method | Defined By
--- | --- | ---
|  | fit(rectangle:Rectangle, into:Rectangle, scaleMode:String = showAll, pixelPerfect:Boolean = false, resultRect:Rectangle = null):Rectangle [static] Calculates a rectangle with the same aspect ratio as the given 'rectangle', centered within 'into'. | RectangleUtil
|  | intersect(rect1:Rectangle, rect2:Rectangle, resultRect:Rectangle = null):Rectangle [static] Calculates the intersection between two Rectangles. | RectangleUtil

Method Detail

fit | () | method

`public static function fit(rectangle:Rectangle, into:Rectangle, scaleMode:String = showAll, pixelPerfect:Boolean = false, resultRect:Rectangle = null):Rectangle`

Calculates a rectangle with the same aspect ratio as the given 'rectangle', centered within 'into'.

This method is useful for calculating the optimal viewPort for a certain display size. You can use different scale modes to specify how the result should be calculated; furthermore, you can avoid pixel alignment errors by only allowing whole-number multipliers/divisors (e.g. 3, 2, 1, 1/2, 1/3).

Parameters

| `rectangle:Rectangle`
| `into:Rectangle`
| `scaleMode:String` (default = `showAll`)``
| `pixelPerfect:Boolean` (default = `false`)``
| `resultRect:Rectangle` (default = `null`)``

Returns

| `Rectangle`

See also

starling.utils.ScaleMode

intersect | () | method |

`public static function intersect(rect1:Rectangle, rect2:Rectangle, resultRect:Rectangle = null):Rectangle`

Calculates the intersection between two Rectangles. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.

Parameters

| `rect1:Rectangle`
| `rect2:Rectangle`
| `resultRect:Rectangle` (default = `null`)``

Returns

| `Rectangle`

Thu Jan 16 2014, 01:11 PM +08:00