编辑操作
大约 1 分钟
编辑操作
实体的基本编辑操作,包括移动、复制、旋转、缩放、镜像、删除等。
在线示例
| 示例 | 描述 | 链接 |
|---|---|---|
| 移动实体 | move 方法示例 | 在线演示{target="_blank"} |
| 复制实体 | clone 方法示例 | 在线演示{target="_blank"} |
| 旋转实体 | rotate 方法示例 | 在线演示{target="_blank"} |
| 缩放实体 | scale 方法示例 | 在线演示{target="_blank"} |
| 镜像实体 | mirror 方法示例 | 在线演示{target="_blank"} |
| 删除实体 | Engine.eraseEntities 用法 | 在线演示{target="_blank"} |
| 显示顺序 | DrawOrder 调整绘制顺序示例 | 在线演示{target="_blank"} |
| 组操作 | GROUP/UNGROUP 创建组和取消组示例 | 在线演示{target="_blank"} |
| 高亮实体 | highLightEntities 和 clearHighLight 用法 | 在线演示{target="_blank"} |
核心 API
移动实体
// 移动实体
entity.move(dx, dy); // 相对移动
entity.move(new Point2D(dx, dy)); // 使用 Point2D
// 批量移动
entities.forEach(e => e.move(100, 50));
Engine.regen();复制实体
// 克隆实体
const cloned = entity.clone();
cloned.move(100, 0); // 移动到新位置
Engine.addEntities(cloned);旋转实体
// 绕点旋转
const center = new Point2D(0, 0);
const angle = Math.PI / 4; // 45 度(弧度)
entity.rotate(center, angle);
Engine.regen();缩放实体
// 绕点缩放
const basePoint = new Point2D(0, 0);
const scaleFactor = 2.0;
entity.scale(basePoint, scaleFactor);
Engine.regen();镜像实体
// 沿直线镜像
const mirrorLine = {
start: new Point2D(0, 0),
end: new Point2D(0, 100)
};
entity.mirror(mirrorLine.start, mirrorLine.end);
Engine.regen();删除实体
// 删除单个实体
Engine.eraseEntities(entity);
// 删除多个实体
Engine.eraseEntities([entity1, entity2, entity3]);