这是我新建的一个节点
var newNode = new cc.Node(jso.bh);
newNode.addComponent(cc.Sprite)
var parent = cc.find("Canvas/rw");
parent.addChild(newNode);
如何在这个节点下动态加载一个已经写好的 javascript ,并执行 javascript 里的 update (dt)
这是我新建的一个节点
var newNode = new cc.Node(jso.bh);
newNode.addComponent(cc.Sprite)
var parent = cc.find("Canvas/rw");
parent.addChild(newNode);
如何在这个节点下动态加载一个已经写好的 javascript ,并执行 javascript 里的 update (dt)
关注
// Define a new function to be dynamically loadedfunction update(dt) {console.log("
Updating with dt:"
, dt);
}
// Dynamically load the function onto the new Nodenew Node.update = update;
// Execute the update function within the new Nodenew Node.update(0.1);
这里我们定义了一个名为update的函数,并将其动态加载到新建的节点new Node上。然后通过调用节点的update方法,执行了这个函数,并传入参数0.1。最终输出结果会在控制台打印出"
Updating with dt: 0.1"
。