Skip to content

行为和脚本

jtopo提供了回调接口,可以写一些脚本类的代码在每一帧绘制前/后执行一些自定义的逻辑。

回调

利用对象的 beforeRender、afterRender回调接口
js
// 组
let groupNode = new Node(null, x, y, width, height);
groupNode.addClass('.group');
layer.addChild(groupNode);

// 标题栏
let titleBar = new Node(titleText);
titleBar.pointerEnabled = false;
titleBar.addClass('.title');

// 每一帧绘制前执行
titleBar.beforeRender = function () {
    titleBar.resize(this.parent.width, 40);
    titleBar.left = -this.parent.width * 0.5;
    titleBar.top = -this.parent.height * 0.5;
};

groupNode.addChild(titleBar);

参考:行为和脚本演示