Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
How to generate different spawn points for objects (Javascript)?

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
                )
            }

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!