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

146
Vistas
How to group tiles in html canvas?

I'm new to canvas Please Help. I have a canvas like in this Image. All these are tile maps I followed MDN Docs to paint the tile on the canvas.

I want to achieve like this. How do I get the group of tiles of same color?

I created a function to know which tile is clicked. I get (col , row) and I also want to get the size of the tile like 1 * 1 or 3 * 3 and so on.

In Canvas.js Getting Coordinates and handling click event

  function getCoords(e) {
    const { x, y } = e.target.getBoundingClientRect();
    const mouseX = e.clientX - x;
    const mouseY = e.clientY - y;
    return [Math.floor(mouseX / 32) + 1, Math.floor(mouseY / 32) + 1];
  }

  const handleClick = (event) => {
    console.log(getCoords(event));
  };
  // some more stuff
  return <canvas ref={canvasRef} {...rest} onMouseDown={handleClick} />;

In index.js

  <main className={styles.main}>
    <div className={styles.tileset_container_selection}></div>
    <div className={styles.canvasContainer}>
      <Canvas draw={draw} />
    </div>
  </main>
about 4 years ago · Santiago Trujillo
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