Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
¿Cómo se calculan los límites de los objetos de desplazamiento lateral en el lienzo HTML?

Estoy haciendo un pequeño sitio web de desplazamiento lateral. Quiero usar un png como 3 elementos en los que se puede hacer clic en el mapa, cada uno de los cuales activa un modal, pero antes de eso estoy tratando de hacer que se desplacen junto con el objeto de fondo y supongo que no entiendo cómo calcular sus límites y qué pasar a la función.

Mi idea aproximada para la lógica de límite de flecha derecha

Y mi tiro en la oscuridad (tratando de seguir el método que usé para desplazar el fondo):

 class ClickSign { constructor(Background, gameWidth, position, modalId) { this.image = document.getElementById('clickImage'); this.bgWidth = Background.width; // Canvas width this.gameWidth = gameWidth; this.position = position; this.modal = document.getElementById(modalId); this.xi = this.position.x; this.width = 43; this.height = 39; this.speed = 5; } // Draw sprite on canvas draw(context) { context.drawImage(this.image, this.position.x, this.position.y, this.width, this.height); } update(input) { clickSign1.draw(ctx); // === MOVEMENT === // If left key && x is less than ??? if (input.keys.indexOf('ArrowLeft') != -1 && this.position.x < this.bgWidth - (this.gameWidth - this.xi)) { this.position.x += this.speed; } if (input.keys.indexOf('ArrowRight') != -1 && this.position.x > this.xi - this.gameWidth) { this.position.x -= this.speed; } } const clickSign1 = new ClickSign(background, canvas.width, {x: 958, y: 364}, "WelcomeModal");
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!