我如何让一个对象在 p5 中面向鼠标?
How do I have an object face the mouse in p5?
我在使对象面向鼠标时遇到问题,网站教程没有帮助!
function draw() {
background(0, backgroundColor2, 0);
cursor('crosshair.png')
frameRate(1000);
angleMode(DEGREES);
imageMode(CORNER)
let a = atan2(mouseY - height / 2, mouseX - width / 2);
rotate(a);
image(gun, width/2, height/2, 40, 40);
}
对象在旋转但是它在 0, 0 上旋转
所以如果你想让物体在屏幕中心旋转,
function draw() {
background(0, backgroundColor2, 0);
cursor('crosshair.png')
frameRate(1000);
angleMode(DEGREES);
imageMode(CORNER)
let a = atan2(mouseY - height / 2, mouseX - width / 2);
translate(width/2, height/2);
rotate(a);
image(gun, 0, 0, 40, 40);
}
这里有一个link让你更好的理解
https://www.youtube.com/watch?v=o9sgjuh-CBM
我在使对象面向鼠标时遇到问题,网站教程没有帮助!
function draw() {
background(0, backgroundColor2, 0);
cursor('crosshair.png')
frameRate(1000);
angleMode(DEGREES);
imageMode(CORNER)
let a = atan2(mouseY - height / 2, mouseX - width / 2);
rotate(a);
image(gun, width/2, height/2, 40, 40);
}
对象在旋转但是它在 0, 0 上旋转
所以如果你想让物体在屏幕中心旋转,
function draw() {
background(0, backgroundColor2, 0);
cursor('crosshair.png')
frameRate(1000);
angleMode(DEGREES);
imageMode(CORNER)
let a = atan2(mouseY - height / 2, mouseX - width / 2);
translate(width/2, height/2);
rotate(a);
image(gun, 0, 0, 40, 40);
}
这里有一个link让你更好的理解 https://www.youtube.com/watch?v=o9sgjuh-CBM