Constructor
new HitContainer()
Properties:
| Name | Type | Description |
|---|---|---|
sampleCount |
Number | 采样个数,如360代表每隔一度采样一次 - 默认:360 |
sampleMinAlpha |
Number | 采样像素点阈值,采样的数据为RGBA中的A 范围在0-255 - 默认:0 |
sampleDist |
Number | 采样衰减距离 - 默认:1像素 |
- Source:
Example
var local = new HitContainer();
local.sampleCount = 720;
local.sampleMinAlpha = 10;
var localSprite = new PIXI.Sprite(res["image_example1"].texture);
localSprite.anchor.set(0.5);
local.addChild(localSprite);
var target = new HitContainer();
var targetSprite = new PIXI.Sprite(res["image_example2"].texture);
targetSprite.anchor.set(0.5);
target.addChild(targetSprite);
local.initBound();
target.initBound();
local.position.set(10,10);
console.log(local.hitTest(target));
Extends
- PIXI.Container
Methods
(static) _addBoundToMatrix() → {Array}
Add local pixel in to a Matrix.
- Source:
Returns:
The matrix after add the local pixel.
- Type
- Array
(static) _caculateBound(Two-dimensional) → {Array}
Caculate bound area for this in polor coordinate.
Parameters:
| Name | Type | Description |
|---|---|---|
Two-dimensional |
Number | array contains binnary numbers. |
- Source:
Returns:
An array contains polor coordinate points.
- Type
- Array
(static) _caculateBoundMatrix() → {Array}
Caculate the matrix base on visible pixel in this container.
- Source:
Returns:
Two-dimensional array contains binnary numbers. 1 means visible and 0 means transparent.
- Type
- Array
(static) _caculateSuerfaceArea() → {Number}
Caculate the area based on pixel.
- Source:
Returns:
Area.
- Type
- Number
(static) _generateMaxEmptyMatrix() → {Array}
Caculate the smallest matrix which can contains both given matrix.
- Source:
Returns:
An empty matrix.
- Type
- Array
(static) _getBoundaryGraphics() → {PIXI.Graphics}
Draw a polygon based on given points in polor coordinate.
- Source:
Returns:
Polygon graphic.
- Type
- PIXI.Graphics
(static) _multiplyMatrix() → {Array}
Matrix 1 and Matrix 2 must have same shape. The method will multiply every item in matrix 1 and 2. This is not Matrix multiplication.
- Source:
Returns:
A new matrix which have a same shape with given matrix contains resault.
- Type
- Array
(static) _polarToPixel(amplitude, phase) → {Point}
Caculate the position in Cartesian coordinate with given point in polar coordinate.
Parameters:
| Name | Type | Description |
|---|---|---|
amplitude |
Number | Amplitude of polar coordinate point. |
phase |
Number | Phase of polar coordinate point. |
- Source:
Returns:
Point in Cartesian coordinate
- Type
- Point
(static) hitTest() → {Boolean}
检测容器是否碰撞了目标区域
- Source:
Returns:
Collision with target area or not
- Type
- Boolean
(static) initBound()
预处理碰撞检测,这个方法必须在碰撞检测前调用。如果容器的边界发生了变化,需要再次调用
- Source:
(static) isInBound()
检测一个全局点是否在边界内
- Source:
(static) testHitArea() → {Number}
检测碰撞面积比例
- Source:
Returns:
The proportion of hit area.
- Type
- Number