@mai3/phaser-sdk
Version:
A UI component library based on the Phaser game engine
38 lines (37 loc) • 1.78 kB
JavaScript
import Utils from "../utils";
var DragUtils = {
setEventInteractive: function (container, baseConfig, hitArea) {
if ((baseConfig === null || baseConfig === void 0 ? void 0 : baseConfig.geomType) === "Circle") {
hitArea = this.createCircleHitArea(container, baseConfig, hitArea);
}
else {
hitArea = this.createRectangleHitArea(container, baseConfig, hitArea);
}
return hitArea;
},
createCircleHitArea: function (container, baseConfig, hitArea) {
var _a, _b;
if (!hitArea)
hitArea = new Phaser.Geom.Circle();
hitArea = hitArea;
var radius = (_a = baseConfig === null || baseConfig === void 0 ? void 0 : baseConfig.radius) !== null && _a !== void 0 ? _a : 0;
var borderWidth = (_b = baseConfig === null || baseConfig === void 0 ? void 0 : baseConfig.borderWidth) !== null && _b !== void 0 ? _b : 0;
hitArea.setPosition(radius + borderWidth, radius + borderWidth);
hitArea.radius = radius + borderWidth;
container.setInteractive(hitArea, Phaser.Geom.Circle.Contains);
return hitArea;
},
createRectangleHitArea: function (container, baseConfig, hitArea) {
if (!hitArea)
hitArea = new Phaser.Geom.Rectangle();
hitArea = hitArea;
var width = Utils.GetValue(baseConfig, "width", container.getBounds().width);
var height = Utils.GetValue(baseConfig, "height", container.getBounds().height);
hitArea.setSize(width, height);
hitArea.setPosition(0, 0);
container.setInteractive(hitArea, Phaser.Geom.Rectangle.Contains);
// console.log("this.width, this.height: ", `${width}, ${height}`);
return hitArea;
},
};
export default DragUtils;