setString do not update

I’m trying to do the update of the point in gmy game but for some reason the setString method is not working.

`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("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++;
    console.log(this.points);
    this.lblPoints.setString(this.points);
}`

I’m making the call to the function addPoint from the AnimationLayer and its working becasue i can see the points in the console.

I’m basically making it the same way as in the parkour tutorial but its not working.
Anyone know what can be hapening?
Thanks!

Hi,

the lblPoints’s color is black
this.lblPoints.setColor(cc.c3(0,0,0));

Is not this reason?

Nop… the background is not black and the lblPoints is visible whith the initial value… it just do not update.

No one has a clue on this?

Hi @santi87

I don’t see any problem in your code, but can you try this this.lblPoints.setString("" + this.points);
If it doesn’t work, can you provide a online link to your game ? Otherwise it will be complicated to debug.

Huabin

I will try to upload it.
Update of the situation.
I’ve changed a bit the way i call the function on StatusLayer
var statusLayer = this.getParent().getChildByTag(TagOfLayer.Status); statusLayer.addPoint();

But its still no working. What i found is that if for example in the init function of StatusLayer I add
this.addPoint();
this works perfectly…so it seems to be an issue when i call the function with the setString from the other layer… any thoughts?

Thanks

Hi @santi87,

Please add a break point at statusLayer.addPoint();, and confirm the “statusLayer” is you want.

Could you please give us a demo to reappear the issue.

Thanks
David