math.random을 사용하여 무대 상단에서 임의로 개체를 놓습니다. 하나의 객체로 작업했습니다. 그러나 객체 수를 6 개로 늘리려면 다음 코드를 추가했습니다. 그러나 나는 "붙어있어"무대 상단에 6 개의 객체가 있습니다. 여기서 내가 뭘 잘못하고 있니? 도움에 감사드립니다.개체가 스테이지 상단에서 멈춰서 떨어지지 않습니다.
private function bombInit(): void {
roachBombArray = new Array();
for (var i:uint =0; i < numBombs; i++) {
roachBomb= new RoachBomb();
roachBomb.x = Math.random() * stage.stageWidth;
roachBomb.vy = Math.random() * 2 -1;
roachBomb.y = -10;
addChild(roachBomb);
roachBombArray.push(roachBomb);
}
addEventListener(Event.ENTER_FRAME, onEntry);
}
private function onEntry(event:Event):void {
for (var i:uint = 0; i< numBombs; i++) {
var roachBomb = roachBombArray[i];
vy += ay;
roachBombArray[i] += vy;
if (roachBombArray[i] > 620) {
removeChild(roachBombArray[i]);
removeEventListener(Event.ENTER_FRAME, onEntry);
오, 어리석은! 나는 그것을 제거했으나 지금은 1034를 변환 할 수 없다. 나는이 오류를 지금 연구 할 것이다 .... 고마워, Adam. – londonbird
아마도 DisplayObject로 removeChild (roachBombArray [i])가 필요할 수도 있습니다. 배열은 입력되지 않으므로 컴파일러는 roachBombArray [i]가 무엇인지 알지 못합니다. –
알았어. 나도 removeChild (roachBombArray [i] .roachBomb)를했는데 둘 다 똑같은 결과를 얻었다 ... 그 폭탄은 여전히 무대의 꼭대기에 붙어있어 움직이지 않을 것이다. lol – londonbird