gpt4 book ai didi

javascript - 我如何让一个对象在 p5 中面向鼠标?

转载 作者:行者123 更新时间:2023-12-03 07:05:41 25 4
gpt4 key购买 nike

我在使对象面向鼠标时遇到问题,网站教程也无济于事!

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);
}

这里有一个链接可以让你更好的理解 https://www.youtube.com/watch?v=o9sgjuh-CBM

关于javascript - 我如何让一个对象在 p5 中面向鼠标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64762089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com