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++ :(
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
properties: {
label_captcha: {
default: null,
type: cc.Label
},
},
onLoad: function () {
this.label_captcha.string = "test"
},
The tutorial is at this link .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.