Namespace: Unit

SINT.Unit

Example

// Get url parameter
console.log(SINT.Unit.getUrlStr('id'));

// Convert deg to Rad
console.log(SINT.Unit.degToRad(30));

// Load json
SINT.Unit.loadJson('*.json').then(function(json) {
    console.log(json);
}, function(error) {
    console.error('loadJson Erro', error);
}

// Post json
let sendData = {'idStr': '***'};
SINT.Unit.postJson('..*.php', sendData).then(function(data) {
    console.log(JSON.parse(data.jsonStr));
}, function(error) {
    console.error('postJson Erro', error);
}

Methods

SINT.Unit.canvasToImage (canvas)HTMLImageElement static

Name Type Description
canvas HTMLCanvasElement optional

the source object of the texture.

Returns:
Type Description
HTMLImageElement
  • img Element.

SINT.Unit.degToRad (degrees)number static

Name Type Description
degrees number optional
Returns:
Type Description
number The number of Rad

SINT.Unit.getImageRGBAData (img, w, h)Array.<number> static

Name Type Description
img HTMLImageElement optional

the source object of the texture.

w number optional

width

h number optional

height

Returns:
Type Description
Array.<number>
  • An array representing the [R, G, B ,A] of the color.

SINT.Unit.getImageXYData (img, w, h)Array.<number> static

Name Type Description
img HTMLImageElement optional

the source object of the texture.

w number optional

width

h number optional

height

Returns:
Type Description
Array.<number>
  • An array representing the [R, G, B] of the color.

SINT.Unit.getPointAngle (pointStart, pointTo)number static

获取两点方向角度

Name Type Description
pointStart SINT.Point
pointTo SINT.Point
Returns:
Type Description
number
Example
var p1 = new SINT.Point(10, 10);
var p2 = new SINT.Point(50, 30);
SINT.Unit.getPointAngle(p1, p2);
//=> Angle

SINT.Unit.getPointDistance (pointStart, pointTo)number static

获取两点距离

Name Type Description
pointStart SINT.Point
pointTo SINT.Point
Returns:
Type Description
number
Example
var p1 = new SINT.Point(10, 10);
var p2 = new SINT.Point(50, 30);
SINT.Unit.getPointDistance(p1, p2);
//=> Distance

SINT.Unit.getTxtImage (txt, size)HTMLImageElement static

Name Type Description
txt string optional

the string of text.

size number optional

the font size of text.

Returns:
Type Description
HTMLImageElement
  • img Element.

SINT.Unit.getUrlStr (name)string static

Name Type Description
name string optional
Returns:
Type Description
string The string url parameter

SINT.Unit.isIntersectsRect (rectA, rectB)boolean static

检测两个显示对象是否相交,一般用于检测碰撞

注意:边缘重叠始终返回true

Name Type Description
rectA SINT.Rectangle
rectB SINT.Rectangle
Returns:
Type Description
boolean
Example
var rect1 = new SINT.Rectangle(10, 10, 50, 50);
var rect2 = new SINT.Rectangle(50, 30, 50, 50);
SINT.Unit.isIntersectsRect(rect1, rect2);
//=> true

SINT.Unit.loadJson (url)Promise static

Name Type Description
url string optional

the json url.

Returns:
Type Description
Promise
  • Promise

SINT.Unit.postJson (url, sendData)Promise static

Name Type Description
url string optional

the json url.

sendData object optional

the object of data.

Returns:
Type Description
Promise
  • Promise

SINT.Unit.rectContainsRect (rect, obj)boolean static

检测一个显示对象是否在另一个矩形内部

注意:边缘重叠始终返回fasle

Name Type Description
rect SINT.Rectangle
obj SINT.Rectangle | SINT.Point
Returns:
Type Description
boolean
Example
var rect1 = new SINT.Rectangle(10, 10, 100, 100);
var rect2 = new SINT.Rectangle(30, 30, 50, 50);
SINT.Unit.isContainsRect(rect1, rect2);
//=> true