[SOLVED] How to copy 1 time in 1 second

Hello, I have a game and there are tracks in the game. I create the tracks in an infinite loop, but it builds very fast. How do I change the code to create 1 track in 1 second?

TileSpawner.prototype.update = function(dt) {
    this.camera = this.camera || this.app.root.findByName('Camera');   
    //var up = new pc.Vec3(-40,0,0);
    var mid = new pc.Vec3(-130,-10,0);                                   //var mid = new pc.Vec3(-50,-10,0);
    //var down = new pc.Vec3(-40,0,0);
    var position = [/*up, down,*/mid/*,mid,mid,mid, mid*/];
    var rand = position[Math.floor(Math.random() * position.length)];
    this.lastTile = this.lastTile.add(rand);


TileSpawner.prototype.spawn = function(position){
    // Create an asteroid at (x,y) drifting towards (direction) with (speed)
       var tile = this.Tile1.clone();
    tile.name = "newTilee";
    tile.enabled = true;
     const enabledChildIndex = Math.floor(Math.random() * tile.children.length);
     tile.children.forEach((child, index) => {
         child.enabled = index === enabledChildIndex;
          return tile;

Hi @Onur_Ozturk,

You need to add a timer, here are two forum posts that provide sample code on that:


Hi @Leonidas, thank you, i’ll try right away

Thank you again. it worked. :slight_smile:

1 Like