mirror of
http://junepve.top:3000/chicrobot/CINC.git
synced 2026-10-29 20:41:29 +08:00
fix(VJ) 修复只能操控一个轮盘的问题
This commit is contained in:
1 parent
8b801b8df0
commit
2b155e41bc
2 files changed
+55
-25
No files matched your search
@@ -163,7 +163,7 @@ export default class SkillTestScene extends Phaser.Scene {
|
||||
isActive: false,
|
||||
base: null,
|
||||
knob: null,
|
||||
pointer: null,
|
||||
activePointer: null,
|
||||
centerX: 0,
|
||||
centerY: 0,
|
||||
radius: 50,
|
||||
@@ -345,14 +345,18 @@ export default class SkillTestScene extends Phaser.Scene {
|
||||
// 添加点击事件
|
||||
button.setInteractive({ useHandCursor: true });
|
||||
button.on('pointerdown', (pointer) => {
|
||||
// 选中技能后,将轮盘中心设置为技能按钮的中心位置
|
||||
this.skillWheel.centerX = x;
|
||||
this.skillWheel.centerY = y;
|
||||
this.skillWheel.base.setPosition(x, y);
|
||||
this.skillWheel.base.setVisible(true);
|
||||
// 只有在技能轮盘未激活时才开始技能施法
|
||||
// 这样可以避免与移动轮盘的指针冲突
|
||||
if (!this.skillWheel.isActive) {
|
||||
// 选中技能后,将轮盘中心设置为技能按钮的中心位置
|
||||
this.skillWheel.centerX = x;
|
||||
this.skillWheel.centerY = y;
|
||||
this.skillWheel.base.setPosition(x, y);
|
||||
this.skillWheel.base.setVisible(true);
|
||||
|
||||
this.skillWheel.activeSkill = skillIndex;
|
||||
this.startSkillCast(pointer);
|
||||
this.skillWheel.activeSkill = skillIndex;
|
||||
this.startSkillCast(pointer);
|
||||
}
|
||||
});
|
||||
|
||||
this.skillWheel.skillButtons.push(button);
|
||||
@@ -372,7 +376,7 @@ export default class SkillTestScene extends Phaser.Scene {
|
||||
// 鼠标移动事件
|
||||
this.input.on('pointermove', (ptr) => {
|
||||
// 只有在技能轮盘激活时才处理
|
||||
if (!this.skillWheel.isActive || this.skillWheel.pointer !== ptr) {
|
||||
if (!this.skillWheel.isActive || this.skillWheel.activePointer !== ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -395,7 +399,18 @@ export default class SkillTestScene extends Phaser.Scene {
|
||||
// 鼠标释放事件
|
||||
this.input.on('pointerup', (ptr) => {
|
||||
// 只有在技能轮盘激活时才处理
|
||||
if (!this.skillWheel.isActive || this.skillWheel.pointer !== ptr) {
|
||||
if (!this.skillWheel.isActive || this.skillWheel.activePointer !== ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 完成技能释放
|
||||
this.finishSkillCast();
|
||||
});
|
||||
|
||||
// 处理指针离开屏幕的情况
|
||||
this.input.on('pointerout', (ptr) => {
|
||||
// 只有在技能轮盘激活时才处理
|
||||
if (!this.skillWheel.isActive || this.skillWheel.activePointer !== ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -410,7 +425,7 @@ export default class SkillTestScene extends Phaser.Scene {
|
||||
startSkillCast(pointer) {
|
||||
// 设置技能轮盘状态
|
||||
this.skillWheel.isActive = true;
|
||||
this.skillWheel.pointer = pointer;
|
||||
this.skillWheel.activePointer = pointer;
|
||||
|
||||
// 显示旋钮和轮盘基础
|
||||
this.skillWheel.knob.setVisible(true);
|
||||
@@ -439,7 +454,7 @@ export default class SkillTestScene extends Phaser.Scene {
|
||||
|
||||
// 重置技能轮盘状态
|
||||
this.skillWheel.isActive = false;
|
||||
this.skillWheel.pointer = null;
|
||||
this.skillWheel.activePointer = null;
|
||||
this.skillWheel.activeSkill = null;
|
||||
|
||||
// 隐藏旋钮和轮盘基础
|
||||
|
||||
+28
-13
@@ -5,7 +5,7 @@ export class VirtualJoystick {
|
||||
this.isActive = false;
|
||||
this.base = null;
|
||||
this.knob = null;
|
||||
this.pointer = null;
|
||||
this.activePointer = null; // 保持单一激活指针,但允许不同指针触发
|
||||
this.centerX = 0;
|
||||
this.centerY = 0;
|
||||
this.radius = 50;
|
||||
@@ -35,13 +35,17 @@ export class VirtualJoystick {
|
||||
bindEvents() {
|
||||
this.scene.input.on('pointerdown', (ptr) => {
|
||||
if (this.isInBase(ptr)) {
|
||||
this.pointer = ptr;
|
||||
this.isActive = true;
|
||||
// 只有在没有激活指针时才设置新指针
|
||||
// 这样可以避免不同触摸点之间的干扰
|
||||
if (!this.isActive) {
|
||||
this.activePointer = ptr;
|
||||
this.isActive = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.scene.input.on('pointermove', (ptr) => {
|
||||
if (this.isActive && this.pointer === ptr) {
|
||||
if (this.isActive && this.activePointer === ptr) {
|
||||
const dx = ptr.x - this.centerX;
|
||||
const dy = ptr.y - this.centerY;
|
||||
const distance = Math.sqrt(dx * dx + dy * dy);
|
||||
@@ -49,12 +53,13 @@ export class VirtualJoystick {
|
||||
if (distance > this.radius) {
|
||||
// 限制在圆内
|
||||
const angle = Math.atan2(dy, dx);
|
||||
ptr.x = this.centerX + Math.cos(angle) * this.radius;
|
||||
ptr.y = this.centerY + Math.sin(angle) * this.radius;
|
||||
const knobX = this.centerX + Math.cos(angle) * this.radius;
|
||||
const knobY = this.centerY + Math.sin(angle) * this.radius;
|
||||
this.knob.setPosition(knobX, knobY);
|
||||
} else {
|
||||
this.knob.setPosition(ptr.x, ptr.y);
|
||||
}
|
||||
|
||||
this.knob.setPosition(ptr.x, ptr.y);
|
||||
|
||||
// 发送相对方向(归一化)
|
||||
const dirX = dx / this.radius;
|
||||
const dirY = dy / this.radius;
|
||||
@@ -63,9 +68,19 @@ export class VirtualJoystick {
|
||||
});
|
||||
|
||||
this.scene.input.on('pointerup', (ptr) => {
|
||||
if (this.pointer === ptr) {
|
||||
if (this.activePointer === ptr) {
|
||||
this.isActive = false;
|
||||
this.pointer = null;
|
||||
this.activePointer = null;
|
||||
this.knob.setPosition(this.centerX, this.centerY);
|
||||
this.scene.events.emit('move-relative', { x: 0, y: 0 }); // 停止
|
||||
}
|
||||
});
|
||||
|
||||
// 处理指针离开屏幕的情况
|
||||
this.scene.input.on('pointerout', (ptr) => {
|
||||
if (this.activePointer === ptr) {
|
||||
this.isActive = false;
|
||||
this.activePointer = null;
|
||||
this.knob.setPosition(this.centerX, this.centerY);
|
||||
this.scene.events.emit('move-relative', { x: 0, y: 0 }); // 停止
|
||||
}
|
||||
@@ -83,9 +98,9 @@ export class VirtualJoystick {
|
||||
*/
|
||||
update() {
|
||||
// 仅在启用时更新
|
||||
if (this.enabled && this.isActive && this.pointer) {
|
||||
const dx = this.pointer.x - this.centerX;
|
||||
const dy = this.pointer.y - this.centerY;
|
||||
if (this.enabled && this.isActive && this.activePointer) {
|
||||
const dx = this.activePointer.x - this.centerX;
|
||||
const dy = this.activePointer.y - this.centerY;
|
||||
|
||||
// 发送相对方向(归一化)
|
||||
const dirX = dx / this.radius;
|
||||
|
||||
Reference in new issue
Block a user