I’m having a hard time dynamicaly setting up fonts. So. I have a json and a png that was generated from playcanvas editor and added to a server. The idea is to have a way to override fonts in a game.
I create my font like this where texture is an array with one element (png) and json is the meta data generated by playcanvas :
var font = new pc.Font(texture, json);
var asset = new pc.Asset(name, “font”, {
url: “”
});
then I try to replace a font on entity like this :
var app = this.app;
var self = this;
var entities = app.root.findByTag(tag);
var entitiesLoaded = 0;
var entitiesTotal = entities.length;
.
.
.
// Start loading all the assets
for(var i = 0; i < entities.length; i++) {
var entity = entities[i];
if (entity.element && entity.element.text) {
console.log('font is: ' + entity.element.Font); //undefined
entity.element.Font = asset.resource;//font previously created
console.log('after font is: ' + entity.element.Font);
}
}
Basically what im working on right now is a simple game which can be customized by hot loading assets from urls. If nothing is found at location, just load the default game asset.