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

273
Visualizações
how to stop images from moving untill the Click me button is clicked in p5.js?
var pic1;
var pic2;
var pic3;
let button;
let posX=0
let posY=0
const rightwall=350;
const height=600;

function preload(){
  pic1=loadImage("5.png")
  pic2=loadImage("iron.jpg")
  pic3=loadImage("slagmetal.jpg")
  
}
function setup() {
  createCanvas(600, 600);
  background(0);
  button =createButton('CLICK ME');
  button.position(0,0);
  button.mousePressed(changeBG);
}
function changeBG() {
  let val = random(255);
  background(val);
}

function draw() {
  background(220);
  text(mouseX + "," + mouseY, 20, 20);

 
  img1=image(pic1, 300, 30, 150, 200)
  img2=image(pic2, posX, 70, 100, 100)
  img3=image(pic3,posX, posY-300,150, 200)
  

  posX=constrain(posX+1,0,rightwall-30)
  posY=constrain(posX-1,posY,height-50)
}

I have created animations of three images and also added a button named as "click me" .how can i perform an event if i click on the button and after that the images start moving or animating.the images are animating on its own .i want to know how could i code so that after clicking on the button image will start moving.images will not move untill and unless clickme button is clicked.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could either:

  • use loop() and noLoop() methods: in setup() add noLoop() and in changeBG() add loop()
  • use a global variable playAnim initialized false, change it to true in changeBG() and in the draw() function, add:
if (playAnim) {
  posX=constrain(posX+1,0,rightwall-30)
  posY=constrain(posX-1,posY,height-50)
}
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