0
如何让鼠标像操纵杆一样移动。这里是我的意思的一个例子,除了这只是向右移动,并且当鼠标完全停在右边时。如果鼠标位于中心位置并移动到鼠标所在的位置,我想让圆圈停止。处理游戏杆初学者
float ballX = 0; // need to keep track of the ball's current position
float ballY = 150;
void setup() {
size(300,300); // standard size
}
void draw() {
background(200); // dull background
float speed = 2.0 * (mouseX/(width*1.0));
println("speed is " + speed); // print just to check
ballX = ballX + speed; // adjust position for current movement
fill(255,0,0);
ellipse(ballX, ballY, 20,20);
}