I’m trying to generate some image elements on run time for a 2D game, and I don’t know if this is the best way to do it:
I tried cloning another element that I already have on the Scene.
console.log('Spawning tile');
const { tileWidth, tileHeight } = this.grid;
const tile = this.prefab.clone();
const localPos = this.prefab.localPosition;
const x = 0;
const y = 800;
tile.setLocalPosition(new pc.Vec3(x, y, 0));
tile.name = `tile x: ${tile.localPosition.data[0]} y: ${tile.localPosition.data[1]}`;
this.entities.push(tile);
But it seems that the cloned element looses the screen reference and that is why I can’t see anything new on the game.
Is there a better way to do it ?