-3
所以我有我的處理代碼,除了一個PVector,其速度不能正常工作並且不與代碼的其餘部分同步以外,一切正常。代碼用於彈跳球,但左上角的代碼沒有明顯的原因偏離屏幕。處理:一個對象忽略語句
PVector location;
PVector velocity;
PVector location2;
PVector velocity2;
PVector location3;
PVector velocity3;
PVector location4;
PVector velocity4;
int size;
int acceleration;
void setup() {
size(640,360);
location = new PVector(0,180);
location2 = new PVector(640,180);
location3 = new PVector(0,180);
location4 = new PVector(640,180);
velocity = new PVector(10,-18);
velocity2 = new PVector(-10,18);
velocity3 = new PVector(-10,18);
velocity4 = new PVector(10,-18);
acceleration = 1;
size = 16;
}
void draw() {
background(255);
velocity.y=velocity.y+acceleration;
velocity2.y=velocity2.y-acceleration;
velocity3.y=velocity2.y-acceleration;
velocity4.y=velocity4.y+acceleration;
location.add(velocity);
location2.add(velocity2);
location3.add(velocity3);
location4.add(velocity4);
//size = size + 1;
if ((location.x > 320) || (location.x < 0)) {
velocity.x = velocity.x * -1;
}
if ((location2.x > width) || (location2.x < 320)) {
velocity2.x = velocity2.x * -1;
}
if ((location3.x > 320) || (location3.x < 0)) {
velocity3.x = velocity3.x * -1;
}
if ((location4.x > width) || (location4.x < 320)) {
velocity4.x = velocity4.x * -1;
}
if ((location.y > height) || (location.y < 0)) {
velocity.y = -18;
}
if ((location2.y > height) || (location2.y < 0)) {
velocity2.y = 18;
}
if ((location3.y > height) || (location3.y < 0)) {
velocity3.y = 18;
}
if ((location4.y > height) || (location4.y < 0)) {
velocity4.y = -18;
}
stroke(0);
fill(0);
ellipse(location.x,location.y,size,size);
ellipse(location2.x,location2.y,size,size);
ellipse(location3.x,location3.y,size,size);
ellipse(location4.x,location4.y,size,size);
}
*代碼片段*旨在與可由瀏覽器「運行」的代碼一起使用,如HTML/CSS/JavaScript。對於像Java這樣的代碼示例,使用*代碼示例*(不是說它與您的問題中的問題有關)。 – Pshemo 2014-10-31 18:18:06
好吧,那麼你是否試圖減少你的代碼來找到問題所在?因爲這是很多手工複製粘貼的複製,而不是一個很好的編程式'ArrayList',您只需循環並執行一次所有必需的操作。有問題的點是case 3,所以刪除所有的1/2/4條目,看看會發生什麼(會發生什麼情況是Processing IDE會立即向您顯示您錯誤的位置,並且您應該在發佈到stackoverflow =之前嘗試過)。 –
2014-10-31 18:21:46