UNPKG

@awayfl/awayfl-player

Version:

Flash Player emulator for executing SWF files (published for FP versions 6 and up) in javascript

199 lines (198 loc) 7.58 kB
/** * Implement and register this class with a b2World to provide debug drawing of physics * entities in your game. */ var b2DebugDraw = /** @class */ (function () { function b2DebugDraw() { this.__fast__ = true; this.m_drawScale = 1.0; this.m_lineThickness = 1.0; this.m_alpha = 1.0; this.m_fillAlpha = 1.0; this.m_xformScale = 1.0; this.m_drawFlags = 0; } //}; /** * Set the drawing flags. */ b2DebugDraw.prototype.SetFlags = function (flags /** uint */) { this.m_drawFlags = flags; }; /** * Get the drawing flags. */ b2DebugDraw.prototype.GetFlags = function () { return this.m_drawFlags; }; /** * Append flags to the current flags. */ b2DebugDraw.prototype.AppendFlags = function (flags /** uint */) { this.m_drawFlags |= flags; }; /** * Clear flags from the current flags. */ b2DebugDraw.prototype.ClearFlags = function (flags /** uint */) { this.m_drawFlags &= ~flags; }; /** * Set the sprite */ b2DebugDraw.prototype.SetSprite = function (sprite) { this.m_sprite = sprite; }; /** * Get the sprite */ b2DebugDraw.prototype.GetSprite = function () { return this.m_sprite; }; /** * Set the draw scale */ b2DebugDraw.prototype.SetDrawScale = function (drawScale) { this.m_drawScale = drawScale; }; /** * Get the draw */ b2DebugDraw.prototype.GetDrawScale = function () { return this.m_drawScale; }; /** * Set the line thickness */ b2DebugDraw.prototype.SetLineThickness = function (lineThickness) { this.m_lineThickness = lineThickness; }; /** * Get the line thickness */ b2DebugDraw.prototype.GetLineThickness = function () { return this.m_lineThickness; }; /** * Set the alpha value used for lines */ b2DebugDraw.prototype.SetAlpha = function (alpha) { this.m_alpha = alpha; }; /** * Get the alpha value used for lines */ b2DebugDraw.prototype.GetAlpha = function () { return this.m_alpha; }; /** * Set the alpha value used for fills */ b2DebugDraw.prototype.SetFillAlpha = function (alpha) { this.m_fillAlpha = alpha; }; /** * Get the alpha value used for fills */ b2DebugDraw.prototype.GetFillAlpha = function () { return this.m_fillAlpha; }; /** * Set the scale used for drawing XForms */ b2DebugDraw.prototype.SetXFormScale = function (xformScale) { this.m_xformScale = xformScale; }; /** * Get the scale used for drawing XForms */ b2DebugDraw.prototype.GetXFormScale = function () { return this.m_xformScale; }; /** * Draw a closed polygon provided in CCW order. */ b2DebugDraw.prototype.DrawPolygon = function (vertices, vertexCount /** int */, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); for (var i /** int */ = 1; i < vertexCount; i++) { this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale); } this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); }; /** * Draw a solid closed polygon provided in CCW order. */ b2DebugDraw.prototype.DrawSolidPolygon = function (vertices, vertexCount /** int */, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); this.m_sprite.graphics.beginFill(color.color, this.m_fillAlpha); for (var i /** int */ = 1; i < vertexCount; i++) { this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale); } this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale); this.m_sprite.graphics.endFill(); }; /** * Draw a circle. */ b2DebugDraw.prototype.DrawCircle = function (center, radius, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.drawCircle(center.x * this.m_drawScale, center.y * this.m_drawScale, radius * this.m_drawScale); }; /** * Draw a solid circle. */ b2DebugDraw.prototype.DrawSolidCircle = function (center, radius, axis, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(0, 0); this.m_sprite.graphics.beginFill(color.color, this.m_fillAlpha); this.m_sprite.graphics.drawCircle(center.x * this.m_drawScale, center.y * this.m_drawScale, radius * this.m_drawScale); this.m_sprite.graphics.endFill(); this.m_sprite.graphics.moveTo(center.x * this.m_drawScale, center.y * this.m_drawScale); this.m_sprite.graphics.lineTo((center.x + axis.x * radius) * this.m_drawScale, (center.y + axis.y * radius) * this.m_drawScale); }; /** * Draw a line segment. */ b2DebugDraw.prototype.DrawSegment = function (p1, p2, color) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha); this.m_sprite.graphics.moveTo(p1.x * this.m_drawScale, p1.y * this.m_drawScale); this.m_sprite.graphics.lineTo(p2.x * this.m_drawScale, p2.y * this.m_drawScale); }; b2DebugDraw.prototype.DrawSquare = function (param1, param2, param3, param4) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, param3.color, param4); this.m_sprite.graphics.beginFill(param3.color, param4); this.m_sprite.graphics.moveTo(param1.x, param1.y); this.m_sprite.graphics.drawRect(param1.x, param1.y, param2.x - param1.x, param2.y - param1.y); }; /** * Draw a transform. Choose your own length scale. * @param xf a transform. */ b2DebugDraw.prototype.DrawTransform = function (xf) { this.m_sprite.graphics.lineStyle(this.m_lineThickness, 0xff0000, this.m_alpha); this.m_sprite.graphics.moveTo(xf.position.x * this.m_drawScale, xf.position.y * this.m_drawScale); this.m_sprite.graphics.lineTo((xf.position.x + this.m_xformScale * xf.R.col1.x) * this.m_drawScale, (xf.position.y + this.m_xformScale * xf.R.col1.y) * this.m_drawScale); this.m_sprite.graphics.lineStyle(this.m_lineThickness, 0x00ff00, this.m_alpha); this.m_sprite.graphics.moveTo(xf.position.x * this.m_drawScale, xf.position.y * this.m_drawScale); this.m_sprite.graphics.lineTo((xf.position.x + this.m_xformScale * xf.R.col2.x) * this.m_drawScale, (xf.position.y + this.m_xformScale * xf.R.col2.y) * this.m_drawScale); }; //virtual ~b2DebugDraw() {} //enum //{ /** Draw shapes */ b2DebugDraw.e_shapeBit = 0x0001; /** Draw joint connections */ b2DebugDraw.e_jointBit = 0x0002; /** Draw axis aligned bounding boxes */ b2DebugDraw.e_aabbBit = 0x0004; /** Draw broad-phase pairs */ b2DebugDraw.e_pairBit = 0x0008; /** Draw center of mass frame */ b2DebugDraw.e_centerOfMassBit = 0x0010; /** Draw controllers */ b2DebugDraw.e_controllerBit = 0x0020; return b2DebugDraw; }()); export { b2DebugDraw };