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
-
Name Type Description canvas
HTMLCanvasElement optional the source object of the texture.
Returns:
Type Description HTMLImageElement - img Element.
-
Name Type Description degrees
number optional Returns:
Type Description number The number of Rad -
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.
-
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.
-
获取两点方向角度
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
-
获取两点距离
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
-
Name Type Description txt
string optional the string of text.
size
number optional the font size of text.
Returns:
Type Description HTMLImageElement - img Element.
-
Name Type Description name
string optional Returns:
Type Description string The string url parameter -
检测两个显示对象是否相交,一般用于检测碰撞
注意:边缘重叠始终返回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
-
Name Type Description url
string optional the json url.
Returns:
Type Description Promise - Promise
-
Name Type Description url
string optional the json url.
sendData
object optional the object of data.
Returns:
Type Description Promise - Promise
-
检测一个显示对象是否在另一个矩形内部
注意:边缘重叠始终返回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