Reputation: 21
Does anyone know how to update the text of a label on the Cocos 2D-x? I created a label on the cocos studio, now I'm trying to acess and change its content through my code.
I'm looking for a concrete line of code in JavaScript but I only found answers in C++ :(
Upvotes: 2
Views: 4828
Reputation: 31
properties: {
label_captcha: {
default: null,
type: cc.Label
},
},
onLoad: function () {
this.label_captcha.string = "test"
},
The tutorial is at this link.
Upvotes: 0
Reputation: 1128
Ok, Let's assume you have a similar line of code to create the Label somewhere in your project (this code may be generated by cocos studio for you):
var label = cc.LabelTTF.create("Label text","Arial","18",cc.TEXT_ALIGNMENT_CENTER);
Now, somewhere in your code you want to modify it's value. Here's the code fore it:
label.setString("new text");
Hope it helps
Upvotes: 2