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

215
Visualizações
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 à 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