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

250
Visualizações
How to use canvas and mouse event to move a circle?

I need some help with a project for school if anyone is willing this is the task we use canvas-javascript'When you start the game, a circle is generated in the center of the screen. We call that circle main circle; ● The player controls the movement of the main circle by moving the mouse. The circle moves across the canvas by following the mouse arrow. More precisely, it is necessary to move the center of the main circle to the direction of the current cursor position on the canvas at a certain speed (for example, 20px / s); ● The game starts when the player moves the mouse (ie the main circle);

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

0

Since you only want to make a circle that follow the mouse, so a combination of mousemove and clientX/clientY will be a good option.

        let div = document.querySelector('#cursor')
        document.querySelector('canvas').onmousemove = function(event){
            //track mouse position and change for custom cursor
            div.style.left = event.clientX-5+'px'
            div.style.top = event.clientY-5+'px'
        };
canvas{
    width: 50vw;
    height: 50vh;
    border: 2px solid red;
}
#cursor{
    width: 10px;
    height: 10px;
    background: red;
    position: absolute;
    top: 25%;
    left: 25%;
    border-radius:50%;
}
<canvas></canvas>
   <div id=cursor></div>

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