I have a game like agar.io and PIELES are used.
The skin is put in the player's name with {
... }
. That is, {nombreDaLaPiel} Nickname
.
The function that hides the name of the skin so that it can not be seen in the name
setName: function(name) {
var reg = /\{([\w]+)\}/.exec(name);
if (reg) if (reg.length === 2) {
this.nameSkin = reg[1].toLowerCase();
this.name = name.replace(reg[0], "").trim();
return;
}
this.name = name;
}
The cell or game ball is a circle, and I want that, having a certain skin , the cell has a certain border color . For that I used:
if (this.name.indexOf("{chicken}") !== -1) {
mainCtx.strokeStyle = "#D00606";
}
But the code does not work for me because indexOf()
does not work when the name of the skin is hidden: as if it does not recognize it.
What can I do?
If I change the next line of the function:
this.name = name.replace(reg[0], "").trim();
Because of this:
this.name = name.trim();
The edge does work, but the skin looks in the name.
Again, what can I do?
If more detail is needed, the complete code: link