使用rect.range(this.node.rotation) 后, onUpdate 时, 边框位置发生改变, 这是怎么回事?
到底如何跟随节点rotation旋转呢?
class Rect extends Editor.Gizmo {
init() {
// 初始化一些参数
}onCreateMoveCallbacks() { cc.error(1000) } onCreateRoot() { // group 函数文档 : http://documentup.com/wout/svg.js#groups this.svg = this._root.group(); let target = this.target; let rect = this.svg.rect(target.width, target.height).attr({ fill: '#63B8FF', 'fill-opacity': 0.2, stroke: '#66CD00', 'stroke-width': 1 }); this.svg.change = (width, height, position) => { // 同步位置; rect.move(position.x - width / 2, position.y - height / 2); rect.size(width, height); rect.range(this.node.rotation) // } } onUpdate() { let target = this.target; let node = this.node; // 获取节点世界坐标 let worldPosition = node.convertToWorldSpaceAR(cc.v2(0, 0)); // 转换世界坐标到 svg view 上 // svg view 的坐标体系和节点坐标体系不太一样,这里使用内置函数来转换坐标 let viewPosition = this.worldToPixel(worldPosition); // 对齐坐标,防止 svg 因为精度问题产生抖动 let p = Editor.GizmosUtils.snapPixelWihVec2(viewPosition); // 移动 svg 工具到坐标 this.svg.change(target.width, target.height, p); }}
module.exports = Rect;
