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

184
Views
El método de dibujo de la clase gameState del servidor no está definido en una subclase extendida en el lado del cliente

Tengo un archivo state.js para el back-end de los archivos socket.io. He definido una lista para todos los jugadores, la clase de Player y una clase de Character extendida donde heredé todos los métodos de la clase de Player .

A continuación se muestra mi código para la clase Player en el lado del servidor:

 class Player { constructor(x,y){ this.x = x; this.y = y; this.radius = 20; this.xVel = 4; this.yVel = 4; this.usingSuper = false; this.superLeft = 3; this.immune = false; this.shield = false; this.duration = 3000; this.cooldown = 5000; } draw() { ctx.beginPath(); ctx.fillStyle = this.color; ctx.arc(this.x, this.y, this.radius, 0, Math.PI*2); ctx.fill(); ctx.closePath(); }

Aquí está mi código para la clase extendida "Max":

 class Max extends Player { // superspeed character constructor(x,y){ super(x,y); this.color = 'yellow'; } useSuper(){ this.superLeft --; this.usingSuper = true; this.xVel = 15; this.yVel = 15; // 5 lines below turns the player color to white for a split second let originalColor = this.color; this.color = 'white'; setTimeout(()=>{ this.color = originalColor; }, 500); setTimeout(()=>{ this.xVel = 4; this.yVel = 4; setTimeout(()=>{ this.usingSuper = false; }, this.cooldown); }, this.duration); }

Y aquí es cuando llamo a la función dibujar en el lado del cliente en main.js

 socket.on('state', (gameState)=>{ ctx.clearRect(0, 0, canvas.width, canvas.height); for (let player in gameState.players){ gameState.players[player].draw(); } })

Cuando ejecuto este código, me da este error en la consola del navegador:

TypeError no detectado: gameState.players[player].draw no es una función en Socket. (main.js:13:35) en Socket.Emitter.emit (index.mjs:136:20) en Socket.emitEvent (socket.js:278:20) en Socket.onevent (socket.js:265:18) en Socket.onpacket (socket.js:235:22) en Manager.Emitter.emit (index.mjs:136:20) en Manager.ondecoded (manager.js:200:14) en Decoder.Emitter.emit (index. mjs:136:20) en Decoder.add (index.js:124:17) en Manager.ondata (manager.js:192:22)

La función de dibujo aún no está definida, incluso cuando la anulo directamente en la subclase Max . ¿Cómo puedo solucionar este problema?

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!