Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda