PIXI Controls: Fix DPad scaling

This commit is contained in:
OleSTEEP 2024-02-02 15:25:05 +03:00
parent 185413ab37
commit 0ddb740430

View file

@ -78,6 +78,7 @@ ONSControls.createDPad = function() {
container.anchor.set(0.5); container.anchor.set(0.5);
for (elem of directions) { for (elem of directions) {
container.addChild(elem); container.addChild(elem);
elem.interactive = true;
elem.anchor.set(0.5); elem.anchor.set(0.5);
} }
directions[0].on("pointerdown", (event) => {this.sendEvent(event, "DPAD_RIGHT")}) directions[0].on("pointerdown", (event) => {this.sendEvent(event, "DPAD_RIGHT")})
@ -207,8 +208,7 @@ ONSControls.updateButtons = function() {
buttons[3].y = -(buttonsSize / 2 + buttonsSize / 4); buttons[3].y = -(buttonsSize / 2 + buttonsSize / 4);
container.width = buttonsSize * 2; container.width = buttonsSize * 2;
container.height = buttonsSize * 2; container.height = buttonsSize * 2;
container.x = ConfigManager.ONSConfig.buttonsX; container.position.set(ConfigManager.ONSConfig.buttonsX, ConfigManager.ONSConfig.buttonsY);
container.y = ConfigManager.ONSConfig.buttonsY;
// Update DPAD // Update DPAD
const dPadSize = ConfigManager.ONSConfig.dPadSize; const dPadSize = ConfigManager.ONSConfig.dPadSize;
@ -216,12 +216,11 @@ ONSControls.updateButtons = function() {
const directions = dpadContainer.children; const directions = dpadContainer.children;
dpadContainer.width = dPadSize; dpadContainer.width = dPadSize;
dpadContainer.height = dPadSize; dpadContainer.height = dPadSize;
dpadContainer.x = ConfigManager.ONSConfig.dPadX; dpadContainer.position.set(ConfigManager.ONSConfig.dPadX, ConfigManager.ONSConfig.dPadY);
dpadContainer.y = ConfigManager.ONSConfig.dPadY;
for (elem of directions) { for (elem of directions) {
elem.width = dPadSize / 5.5; elem.width = this.controlsCanvas.vh(0.12) / 2;
elem.height = dPadSize / 5.5; elem.height = this.controlsCanvas.vh(0.12) / 2;
elem.interactive = true; elem.cursor = 'pointer';
} }
directions[0].x = directions[0].width; directions[0].x = directions[0].width;
directions[1].y = directions[1].height; directions[1].y = directions[1].height;
@ -231,24 +230,20 @@ ONSControls.updateButtons = function() {
// Update LB/RB // Update LB/RB
const LBsprite = this.LBsprite const LBsprite = this.LBsprite
const RBsprite = this.RBsprite const RBsprite = this.RBsprite
LBsprite.x = ConfigManager.ONSConfig.LBX; LBsprite.position.set(ConfigManager.ONSConfig.LBX, ConfigManager.ONSConfig.LBY);
LBsprite.y = ConfigManager.ONSConfig.LBY;
LBsprite.width = ConfigManager.ONSConfig.bumpersWidth; LBsprite.width = ConfigManager.ONSConfig.bumpersWidth;
LBsprite.height = ConfigManager.ONSConfig.bumpersHeight; LBsprite.height = ConfigManager.ONSConfig.bumpersHeight;
RBsprite.x = ConfigManager.ONSConfig.RBX; RBsprite.position.set(ConfigManager.ONSConfig.RBX, ConfigManager.ONSConfig.RBY);
RBsprite.y = ConfigManager.ONSConfig.RBY;
RBsprite.width = ConfigManager.ONSConfig.bumpersWidth; RBsprite.width = ConfigManager.ONSConfig.bumpersWidth;
RBsprite.height = ConfigManager.ONSConfig.bumpersHeight; RBsprite.height = ConfigManager.ONSConfig.bumpersHeight;
// Update additional // Update additional
const showButton = this.ShowButton; const showButton = this.ShowButton;
// const switchButton = this.switchButton; // const switchButton = this.switchButton;
showButton.x = ConfigManager.ONSConfig.showX; showButton.position.set(ConfigManager.ONSConfig.showX, ConfigManager.ONSConfig.showY);
showButton.y = ConfigManager.ONSConfig.showY;
showButton.width = ConfigManager.ONSConfig.additonalSize; showButton.width = ConfigManager.ONSConfig.additonalSize;
showButton.height = ConfigManager.ONSConfig.additonalSize; showButton.height = ConfigManager.ONSConfig.additonalSize;
// switchButton.x = ConfigManager.ONSConfig.switchX; // switchButton.position.set(ConfigManager.ONSConfig.switchX, ConfigManager.ONSConfig.switchY);
// switchButton.y = ConfigManager.ONSConfig.switchY;
// switchButton.width = ConfigManager.ONSConfig.additonalSize; // switchButton.width = ConfigManager.ONSConfig.additonalSize;
// switchButton.height = ConfigManager.ONSConfig.additonalSize; // switchButton.height = ConfigManager.ONSConfig.additonalSize;
console.log("ONSControls: Controls updated"); console.log("ONSControls: Controls updated");