Tengo un sprite de juego que quiero mover verticalmente, y normalmente esto sería fácil con this.x += number
, excepto por el hecho de que las x/y del sprite son relativas a su ángulo. esto puede ser un poco confuso, así que tengo un ejemplo aquí.
en otros casos, donde la imagen no se cargará de otra cosa, tengo un enlace de imagen de ejemplo
puede ser un poco largo aquí está el código básico
this.update = function() { ctx = myGameArea.context; if (type == "image") { ctx.save(); ctx.translate(300, 200); ctx.rotate(this.angle); ctx.translate(this.x, this.y) ctx.drawImage(this.image, this.width / -2, this.height/ -2, this.width, this.height); ctx.restore(); }else { ctx.save(); ctx.translate(this.x, this.y); ctx.rotate(this.angle); ctx.fillStyle = color; ctx.fillRect(this.width / -2, this.height / -2, this.width, this.height); ctx.restore(); } } function framethingupdate() { gamething.update(); }
debido a ciertos problemas, no puedo ejecutar o proporcionar una demostración, sin embargo, si se necesita el código completo, puede encontrarlo aquí: código completo