如何解决在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,40,40);
}
这里是一个链接,可让您更好地了解 https://www.youtube.com/watch?v=o9sgjuh-CBM
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。