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

212
Vistas
how do I match my background image to my set Canvas size?

const canvas = document.querySelector('canvas');
const c = canvas.getContext('2d')
const CANVAS_WIDTH = canvas.width = 1024
const CANVAS_HEIGHT = canvas.height = 576

//fillRect() is a method of the 2d drawing context object.
c.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT)
const gravity = 0.5

//adding the {} within () allows the values to operate without it having to be in order.

    const backgroundLayer1 = new Sprite({
        position: {
            x: 0,
            y: 0
        },
        imageSrc: './img/background/background_layer_1.png', 
    })

    const backgroundLayer2 = new Sprite({
        position: {
            x: 0,
            y: 0,
        },
        
        imageSrc: './img/background/background_layer_2.png', 
    })

    const backgroundLayer3 = new Sprite({
        position: {
            x: 0,
            y: 0
        },
        imageSrc: './img/background/background_layer_3.png', 
    })
    .
    .
    .
    function animate() {
    window.requestAnimationFrame(animate)
    c.fillStyle = "black"
    c.clearRect(0, 0, canvas.width, canvas.height)
    backgroundLayer1.update()
    backgroundLayer2.update()
    backgroundLayer3.update()
    }

The code above is just the part of the code that covers the BG. Here it shows the size of the canvas and the BG image but when I Run the code the BG image comes out small only in the top left corner. Please let me know if I need to provide more code if it helps.

about 4 years ago · Juan Pablo Isaza
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