so I was tasked to create a game in visual studio code using phaser.io for help. At the moment, I was told to bold a specific word in a sentence that is in quotation marks, but I am not sure how to do show. This is all in a Javascript file.
const text3 = this.add.text(
650,
460,
"Answer: Have a budget plan to save up money to buy it.",
{ fontFamily: "Roboto", fill: "black" }
);
I am suppose to bold the word "Answer" that is in quotation marks, so it should look like such
const text3 = this.add.text(
650,
460,
"**Answer**: Have a budget plan to save up money to buy it.",
{ fontFamily: "Roboto", fill: "black" }
);
Can someone help me out with this?
Try this
const text3 = this.add.text(
650,
460,
"Answer: Have a budget plan to save up money to buy it.",
{ fontFamily: "Roboto", fill: "black" }
);
text3.addFontWeight('bold', 0); // 0 means the start of the text
text3.addFontWeight('normal', 6); // change it to normal starting from index 6 of the text
See: Documentation
Phaser 3
Inline styling of text is no supported natively, as per this github issue .
It's worth mention rexBBCodeText & rexTagText that could help you to manage inline style in a better way (using BBCode or html tags).
In any case, if you really need to use this syntax **Answer**
, it's better to split the string and manage each part alone.
Phaser 2 CE
This old version manage text in a different way and you could use addFontWeight
specifying the beginning inside the string of the change in weight.
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.