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

298
Vistas
Uncaught ReferenceError: Cannot access 'Sprite' before initialization

I'm currently programming a web game and I'm stuck here, could someone help me? I've tried different ways but I've been stuck here for a few hours so I thought I'd write here, I'm a junior programmer and I'm using this page for the first time, if I've described something wrong I apologize.

Uncaught ReferenceError: Cannot access 'Sprite' before initialization

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

class Sprite {
    constructor({position, velocity, imageSrc}) {
        this.position = position
        this.velocity = velocity
        this.width = 50
        this.height = 150
        this.image = new Image()
        this.image.src = imageSrc
    }
    draw() {
      c.drawImage(this.image, this.position.x, this.position.y)

    }
    update() {
        this.draw()
    }
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to initialize a class before use. Move your class declaration on top:

class Sprite {
  // ...
}

const backgorund = new Sprite({
   // ...
})
about 4 years ago · Juan Pablo Isaza Denunciar
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