4
旋轉如何讓聖誕老人跟着鼠標旋轉和自己的速度,而不是鼠標速度?
現在鼠標在哪裏 - 它的目的地,在哪裏與自己的速度去聖誕老人。
聖誕老人隨速度旋轉。
我該怎麼做?
game.js
var canvas, ctx, player
function init() {
canvas = document.getElementById("canvas")
ctx = canvas.getContext("2d")
resizeCanvas()
player = new Player(
ctx,
canvas.width/2,
canvas.height/2 + 100
)
window.onresize = resizeCanvas
canvas.onmousemove = mousemove
}
function mousemove(e) {
player.x = e.clientX * devicePixelRatio
player.y = e.clientY * devicePixelRatio
}
function render() {
ctx.clearRect(0, 0, canvas.width, canvas.height)
player.draw()
}
function step() {
render()
requestAnimationFrame(step)
}
init()
step()