0
我使用的代碼從這個小提琴多個對象的隨機運動:createJS - 集裝箱
https://codepen.io/rauluranga/pen/KwoBdE
我想使用此代碼,使我enemies.container每個對象都有隨機運動。
代碼:
if(ticker2 > 80) {
xT2 = Math.ceil(Math.random()*600) + 100;
yT2 = Math.ceil(Math.random()*400) + 100;
ticker2 = 0;
}
ticker2++;
xP2 += (xT2 - xP2)/15;
yP2 += (yT2 - yP2)/15;
wingman2.x += ((xP2 - wingman2.x)/60);
wingman2.y += ((yP2 - wingman2.y)/60);
我試了一下,到目前爲止:
做一個for循環遍歷所有的enemies.length併爲每個敵人創建一個新的XT和YT號:
if(ticker > 50) {
xT.length = 0;
yT.length = 0;
for(var count = 0; count < enemies.children.length; count++) {
xT.push(Math.ceil(Math.random()*700) + 100);
yT.push(Math.ceil(Math.random()*500) + 100);
}
ticker = 0;
}
ticker++;
現在,我被困在向前邁進。
for(var count = 0; count < xT.length; count++) {
xP += (xT[count] - xP)/15;
yP += (yT[count] - yP)/15;
}
for(var count = 0; count < enemies.children.length; count++) {
enemies.children[count].x += ((xP - enemies.children[count].x)/60);
enemies.children[count].y += ((yP - enemies.children[count].y)/60);
}
我試着做更多的forloops和數組,但零成功。