0

I am having trouble creating different spawn points for each object, as shown below. I have 4 spawn points set up, however, all objects are spawning from i = 0. Any feedback would be great!

Thanks,

            var spawnX = 0;
            var spawnY = 0;

            function getSpawnX(i){
                if(i=0 || 4 || 8 || 12 || 16 || 20 || 24 || 28){
                    spawnX = width/4
                    return spawnX;
                }else{
                    spawnX = width/2
                    return spawnX;
                }
            }

            function getSpawnY(i){
                if(i=0 || 4 || 8 || 12 || 16 || 20 || 24 || 28){
                    spawnY = height/4
                    return spawnY;
                }else{
                    spawnY = width*(3/4)
                    return spawnY;
                }
            }

            for (let i = 0; i < numParticles; i++) { //creates array of objects 
             for each rect
                p[i] = particle.create(
                    //spawn points
                    getSpawnX(i), //x starting x point
                    getSpawnY(i), //y starting y point
                    Math.random() * 45 + 45 , // random  w (minimum 45, max 90)
                    Math.random() * 45 + 45 , // random h (minimum 45, max 90)
                    Math.random() * 15 * randomSign(), //random dx
                    Math.random() * 15 * randomSign() //random dy
                )
            }

  • In your if statements, you need two or three equal statements. E.g. `if(i == 0 || i == 4 || ...)` – code Nov 28 '21 at 22:51
  • Using || inside your if is alright. That's not the problem. The problem is that you are setting i to 0 instead of comparing it to 0. Remember to use TWO '=' symbrols for comparison in your "IF" statements. The rest looks fine. – Cristopher Rosales Nov 28 '21 at 22:54
  • Thank you code and Cristopher, I was able to get it to work! – Antoniosant Nov 28 '21 at 23:14

0 Answers0