Joseph

Members
  • Content Count

    5
  • Joined

  • Last visited

  1. Joseph

    set interval

    let i = 0 function gameLoop() { setTimeout(() => drawRandomSprites() , i * 3000) i++
  2. Joseph

    set interval

    function drawRandomSprites() { let images = ["images/Tree_3.png", "images/crate.png"] let randomIndex randomIndex = Math.floor(Math.random() * images.length); sprite = new PIXI.Sprite.from(images[randomIndex]) sprite.anchor.set(0.5) sprite.x = 1200 sprite.y = 420 console.log(randomIndex) app.stage.addChild(sprite) }
  3. Joseph

    set interval

    thank you Ivan I actually had a classmate solve this question for me. but now Ive stumbled upon a new problem. I am looping in sprites trying to assign movement to sprites and its working but when the loop runs again the sprites movement is reassigned to the next sprite and the for sprite movement stops function gameLoop() if (!sprite) { return null } else { sprite.x -= 1 }
  4. Joseph

    set interval

    I am trying to run a set interval to draw a tree every 3000 milliseconds in my game loop. however it runs according to the ticker and draw too many trees. function gameLoop() { drawRandomTree() } function drawRandomTree() { setInterval( drawTree(), 3000 ) } function drawTree() { tree = new PIXI.Sprite.from("images/Tree_3.png") tree.anchor.set(0.5) tree.x = Math.random() * 800 tree.y = app.view.height / 1.89 app.stage.addChild(tree) \ }