Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
I am coding gravity but its stuttering

I am making a 2d platformer and am working on gravity and collision but when I actually get the collision working my gravity became very stuttery, is there a way to fix this? here is code:

gravity(){
    if(this.y <= 400 - this.scale){
      let gc = get(this.x, this.y + 20);
      print(gc);
      if(gc[0] == 0 && gc[1] == 0 && gc[2] == 255 && gc[3] == 255){
        return;
      }
      else{
        this.y += 2;
      }
    }
  }

edit: I have heard this should be working so I will provide more code to see if it helps. here is the function that runs everything:

    var groundArray = [];
    groundArray[0] = [0];
    groundArray[1] = [0];
    groundArray[2] = [0];
    groundArray[3] = [0];
    groundArray[4] = [0];
    groundArray[5] = [0];
    groundArray[6] = [0];
    groundArray[7] = [0];
    groundArray[8] = [1];
    groundArray[9] = [1, 1];
    
    function setup() {
      noStroke();
      createCanvas(400, 400);
      for(let y = 0; y < groundArray.length; y++){
        for(let x = 0; x < groundArray[y].length; x++){
            if(groundArray[y][x] != 0){
              groundArray[y][x] = new ground(x * 40, y * 40);
            }
        }
      }
    }
    
    var play = new player(35, 0, 20);
    
    function draw() {
      background(255);
      for(let y = 0; y < groundArray.length; y++){
        for(let x = 0; x < groundArray[y].length; x++){
            if(groundArray[y][x] != 0){
              groundArray[y][x].draw();
            }
        }
      }
      play.draw();
      
      play.gravity();
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Normally a function named draw() is called every frame, is that what's happening here? It looks like it. In which case, do you really want to be calling new ground(x * 40, y * 40) every frame, wouldn't this object creation be better placed in setup()?

I suspect it's unnecessary and possibly doing expensive initialization work every frame, but without seeing the full source code one can't be sure.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda