Skip to content

Commit c508392

Browse files
committed
✨ 按中括号键缩放摄像机时,跟随屏幕中心缩放,而不是鼠标指针位置
1 parent c3ac70f commit c508392

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

app/src/core/stage/Camera.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,33 @@ export namespace Camera {
144144
const diffViewVector = Renderer.transformWorld2View(targetLocationByScale);
145145
dealCameraScale();
146146
if (scaleCameraByMouseLocation) {
147-
setLocationByOtherLocation(targetLocationByScale, diffViewVector);
147+
if (tickNumber > tickNumberUpper) {
148+
setLocationByOtherLocation(targetLocationByScale, diffViewVector);
149+
}
148150
}
149151
// 循环空间
150152
if (limitCameraInCycleSpace) {
151153
dealCycleSpace();
152154
}
155+
tickNumber++;
156+
}
157+
/**
158+
* 当前的帧编号
159+
*/
160+
let tickNumber = 0;
161+
/**
162+
* 多少帧以后,才能继续跟随鼠标缩放
163+
*/
164+
let tickNumberUpper = 0;
165+
166+
export function zoomInByKeyboard() {
167+
Camera.targetScale *= 1.2;
168+
tickNumberUpper = tickNumber + 5 * 60;
169+
}
170+
171+
export function zoomOutByKeyboard() {
172+
Camera.targetScale *= 0.8;
173+
tickNumberUpper = tickNumber + 5 * 60;
153174
}
154175

155176
/**

app/src/core/stage/stageObject/entity/Section.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class Section extends ConnectableEntity {
144144
// 群友需求:希望Section框扩大交互范围,标题也能拖动
145145
const newRect = new Rectangle(rectangle.location.clone(), new Vector(rectangle.size.x, 50));
146146
this._collisionBoxNormal.shapeList.push(newRect);
147-
console.log(newRect);
147+
// console.log(newRect);
148148
// 调整折叠状态
149149
this._collisionBoxWhenCollapsed = this.collapsedCollisionBox();
150150
}

app/src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async function registerKeyBinds() {
201201
shift: false,
202202
})
203203
).down(() => {
204-
Camera.targetScale *= 1.2;
204+
Camera.zoomInByKeyboard();
205205
});
206206

207207
(
@@ -211,7 +211,7 @@ async function registerKeyBinds() {
211211
shift: false,
212212
})
213213
).down(() => {
214-
Camera.targetScale *= 0.8;
214+
Camera.zoomOutByKeyboard();
215215
});
216216

217217
(

0 commit comments

Comments
 (0)