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

210
Views
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
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!