Javascript move target around screen?

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

So I'm working on a basic shooter, part of which involves moving a target around the screen. I'm using babylon.js as the engine and my goal is to have the target appear for 0.75 seconds on the screen, then disappear for 0.5 seconds, then reappear at a different random location. The current code I have for that is this:

function moveTarget(canvas, scene){
  setTimeout( function (){
    scene.meshes[10].visibility = 0; //how I access the target object
    randX = genRandNum(minX, maxX); //This is a separate function that works
    randY = genRandNum(minY, maxY);
    scene.meshes[10].position = new BABYLON.Vector3(randX, randY, 
                 scene.meshes[10].position.z);
    scene.meshes[10].visibility = 1;
    x ++;
    if (x < amount){
      moveTarget(canvas, scene);
    }
  }, tarDuration * 1000)

  }

which succeeds in everything except the 0.5 second delay between appearances of the target, ie currently it flashes from location to location with no space in between. I'm thinking that I need a second setTimeout but I'm not entirely sure how to include that or where it would go. Any pushes in the right direction would be much appreciated.

asked 29 secs ago

نویسنده : استخدام کار بازدید : 61 تاريخ : پنجشنبه 28 ارديبهشت 1396 ساعت: 9:08

فهرست وبلاگ