diff --git a/src/services/editor/editor-robot.service.ts b/src/services/editor/editor-robot.service.ts index 820671f..92dffb0 100644 --- a/src/services/editor/editor-robot.service.ts +++ b/src/services/editor/editor-robot.service.ts @@ -321,16 +321,20 @@ export class EditorRobotService { const pen = this.ctx.getPenById(id); if (!pen) return; - // [关键修复] 强制同步可见性,防止因底层库时序问题导致的状态不一致。 - // 在回放模式下,上游的 setValue 可能不会立即生效,导致此处的 pen.visible 仍为 false。 - if (pen.visible === false) { + // [修复] 只有在机器人有有效位置数据时才设置为可见,避免在初始位置闪烁 + const hasValidPosition = (pen.x !== undefined && pen.y !== undefined && + (pen.x !== 0 || pen.y !== 0)) || + (newPosition?.x !== undefined && newPosition?.y !== undefined && + (newPosition.x !== 0 || newPosition.y !== 0)); + + // 只有在机器人有有效位置且当前不可见时,才设置为可见 + if (hasValidPosition && pen.visible === false) { this.ctx.setValue({ id, visible: true }, { render: false, history: false, doEvent: false }); } const icon = this.getRobotStatusIcon(pen); - // 鉴于上面已经强制设置了 visible,此处直接使用 true 或重新检查 pen.visible 均可。 - // 为确保逻辑的健壮性,我们直接使用 true。 - const robotVisible = true; + // 机器人可见性取决于是否有有效位置数据 + const robotVisible = hasValidPosition; const baseW = (pen as any).iconWidth ?? 42; const baseH = (pen as any).iconHeight ?? 76;