Editor.Gizmo.prototype.registerMoveSvg(svg, args, opts)

Register a moveable svg element. When the svg element is moved, the callback created from onCreateMoveCallbacks will be called.

  • svg Svg Element - The svg element which can move.
  • args Object | Array - The args will parse to callback, you can check which svg element is moved with the args.
  • opts Object - The options you can set.

    • cursor String - The move mouse cursor.
    • ignoreWhenHoverOther Boolean - Will ignore the mouse down event on this svg element if hover on other svg element.

      this.registerMoveSvg(moveRectSvg, 'move-rect');
      this.registerMoveSvg(moveAnchorSvg, 'move-anchor-rect');


Record undo changes, generally gizmo will record changes automatically.


Commit undo changes, generally gizmo will commit changes automatically

Editor.Gizmo.prototype.adjustValue(targets, keys, minDifference)

Adjust value to avoid value's fractional part to be too long.

  • targets [Object] - The target which should adjust.
  • keys String (optional) - If not specified, then will adjust all available properties on target.
  • minDifference Number (optional) - The decimal precision, default is Editor.Gizmo.prototype.defaultMinDifference()
this.adjustValue(this.node, ['position']);


Convert cocos2d world position to svg position.


Convert svg position to cocos2d world position.


Convert cocos2d scene position to svg position.


Convert svg position to cocos2d scene position.

Inherit Methods


Call when init a gizmo, you can reimplement this function to do your self init.

Default implement:

init () {
    // init logic


There three layer types now: background, scene, foreground, generally we add gizmo to scene layer.

Default implement:

layer () {
    return 'scene';


Whether the gizmo is visible, if you want the gizmo always be visible, then return true.

Default implement:

visible () {
    return this.selecting || this.editing;


Whether the gizmo is dirty, the gizmo will only update when gizmo is dirty. If you want to update gizmo every frame then return true.

Default implement:

dirty () {
    return this._viewDirty() || this._nodeDirty() || this._dirty;


This function will call when create the root svg element for a gizmo. You can implement this function to custom your gizmo creation.

onCreateRoot () {
    // your implement
    var tool = this._root.group();


This callback return from the function will call when the moveable svg element is moved.

The callback should include methods with:

  • start(x, y, event, ...args) - Called when mouse press on the svg
    • x Number - Press x position
    • y Number - Press y position
    • event MouseEvent - The mouse event
    • args - The arguments parsed from registerMoveSvg
  • update(dx, dy, event, ...args) - Called when mouse move on the svg
    • dx Number - Horizontal move distance from current mouse position to start mouse position
    • dy Number - Vertical move distance from current mouse position to start mouse position
    • event MouseEvent - The mouse event
    • args - The arguments parsed from registerMoveSvg
  • end(updated, event, ...args) - Called when mouse release on the svg
    • updated Boolean - Whether the mouse moved
    • event MouseEvent - The mouse event
    • args - The arguments parsed from registerMoveSvg
onCreateMoveCallbacks () {
    return {
        start: (x, y, event, ...args) => {

        update: (dx, dy, event, ...args) => {

        end: (updated, event, ...args) => {



Used for Editor.Gizmo.prototype.adjustValue.

The default min difference will be:

defaultMinDifference() {
    return Editor.Math.numOfDecimalsF(1.0/this._view.scale);



Get node of the gizmo.


Get current nodes of the gizmo.


Get current top nodes of the gizmo.


Whether the gizmo is selecting.


Whether the gizmo is editing.


Whether the gizmo is hovering.

条与 "" 相匹配的结果

    没有与 "" 匹配的结果