Can any body tell me, how can I use the value saved in one node be use in another node. Being specific, if I use mouse event and generate a value in one object, how can i use that in another object?
It is very simple , assume you have component class that store mouse position as following code
//MousePos.component.js
cc.Class({
extends: cc.Component,
properties: {
mousePos: cc.p(0,0)
},
});
also a component that you want to access the mousePos from it
//ReadMousePos.component.js
var mousePos = require("MousePos.component")
cc.Class({
extends: cc.Component,
properties: {
mousePosNode: {
default:null,
type: mousePos
},
label: {
default: null,
type: cc.Label
},
},
onBtnClick:function(){
this.label.string = this.mousePosNode.mousPos;
}
});
where mousePosNode is the node that has MousePos.component component.
also you can use this.mousePosNode.getComponent("MousePos.component").mousePos if the type of mousePosNode is cc.Node .
Thank you very much, it was very helpful.