Hello… i’m having an issue trying to invoke functions in other layers.
I’m on the PlayScene.js and i want to invoke the function addPoints which i have in StatusLayer.js bu i can’t.
i tried statusLayer.addPoint(); but it seems not to work.
Any suggestions?
Thnks
Sorry, we can’t help you with your own implementation unless you give us some code of PlayScene and StatusLayer
Sorry… here i add my code
var PlayScene = cc.Layer.extend({
animationLayer:null,
statusLayer:null,
onEnter:function(){
this._super();
//add 3 layers in the right order
this.addChild(new BackgroundLayer(), 0, TagOfLayer.background);
this.addChild(new AnimationLayer(),0, TagOfLayer.Animation );
this.addChild(new StatusLayer(),0, TagOfLayer.Status);
this.animationLayer = this.getChildByTag(TagOfLayer.Animation);
this.statusLayer = this.getChildByTag(TagOfLayer.Status);
this.animationLayer.createPlayer();
this.animationLayer.startCreatingEnemies();
this.animationLayer.startCheckCollision(this);
},
checkCollision:function(){
if(this.enemy[this.f] != null && this.enemyAction[this.f].isDone()){
//console.log("enemy: " + parseInt(this.enemy[this.f].getPosition().x));
//console.log("player: " + this.player.getPosition().x);
if(this.enemy[this.f].getType() == this.player.getType()){
console.log("vivio");
this.statusLayer.addPoint();
this.f++;
//console.log("i: " + this.i + " f: " + this.f);
}
else{
console.log("murio");
this.f++;
//console.log("i: " + this.i + " f: " + this.f);
}
}
else{
//console.log("nulooo");
}
},
});
var StatusLayer = cc.Layer.extend({
lblPoints:null,
points:0,
ctor:function(){
this._super();
this.init();
},
init:function(){
this._super();
var winSize = cc.Director.getInstance().getWinSize();
this.lblPoints = cc.LabelTTF.create("Coins:0", "Helvetica", 20);
this.lblPoints.setColor(cc.c3(0,0,0));
this.lblPoints.setPosition(cc.p(winSize.width - (winSize.width - 50), winSize.height - 20));
this.addChild(this.lblPoints);
},
addPoint:function(){
this.points++;
this.lblPoints.setString(this.points);
}
});
I’m trying to follow the tutorail of parkour on javascript and tried the TagOfLayer but to be honest i don’t know very well how it works so it do not work for me jaja…
Hope this helps you to help me jeje…
Thanks
Have you used Chrome developer tool to inspect your code and add break point in checkCollision
function ? You can verify
StatusLayer === undefined
this.statusLayer instanceof StatusLayer
- Step into addPoint function to see if it really get called.
- If all these tests get through, you can maybe step into setString to see whether the string in LabelTTF is correctly set.
Huabin