2013-04-10 4 views
0

작은 게임을 만들고 있는데,이 게임 내에서 일정한 시간이 지나면 레벨이 바뀝니다. 그것은 주자입니다. 그래서 각 플랫폼에서 100px마다 플랫폼 섹션을 만들면 배너, 동전 또는 장애물을 넘길 수 있습니다. 이것은 for 루프에서 작성됩니다. 내 문제는 수준을 전환 할 때 무언가에 장애물이있는 경우 하위를 제거하려고하지만 var가 if 문에만 존재하기 때문에 _obstacle.removeCild()를 실행할 수 없습니다. 레벨 변경 기능. 아래 코드 :AS3 어린이를 비공개 변수로 변경

//Go through all the sections and add obstacles or banners or coins based on a chance value. If an obstacle is created in a section, a coin can't be created in the same section 
for (_indexA = 0 ; _indexA < _indexB ; _indexA++) 
{ 
    if (Math.random() < _bannerChance && _bannerDelay == 0) 
    { 
//Create banner 
     var _banner:MC_banner = new MC_banner(); 
     _platformArray[_platformArray.length - 1].addChild(_banner); 
     _banner.x = _platformArray[_platformArray.length - 1].getChildAt(_indexA).x + _platformArray[_platformArray.length - 1].getChildAt(_indexA).width * 0.5; 
     _banner.gotoAndStop(Math.ceil(Math.random() * _banner.totalFrames)); 
     _banner.rotation = int(Math.random() * 4 + 0.5) - 2; 
     _banner.cacheAsBitmap = true; 
     _bannerDelay = 100; 
    } 
    else if (Math.random() < _obstacleChance) 
    { 
     var _obstacle:MC_obstacle = new MC_obstacle(); 
     var _obstacle2:MC_obstacle2 = new MC_obstacle2(); 
//CUSTOM LEVEL CHANGE 
      if (_currentLevel == 1){ 
       _platformArray[_platformArray.length - 1].addChild(_obstacle); 
       _obstacle.x = _platformArray[_platformArray.length - 1].getChildAt(_indexA).x + _platformArray[_platformArray.length - 1].getChildAt(_indexA).width * 0.5; 
       _obstacle.gotoAndStop(Math.ceil(Math.random() * _obstacle.totalFrames)); 
       _obstacle._state = 0; 

      } 

      if (_currentLevel == 2){ 
       _platformArray[_platformArray.length - 1].addChild(_obstacle2); 
       _obstacle2.x = _platformArray[_platformArray.length - 1].getChildAt(_indexA).x + _platformArray[_platformArray.length - 1].getChildAt(_indexA).width * 0.5; 
       _obstacle2.gotoAndStop(Math.ceil(Math.random() * _obstacle2.totalFrames)); 
       _obstacle2._state = 0; 
      } 
    } 
    else if (Math.random() < _coinChance) 
    { 
//Create coin 
     var _coin:MC_coin = new MC_coin(); 
     _platformArray[_platformArray.length - 1].addChild(_coin); 
     _coin.x = _platformArray[_platformArray.length - 1].getChildAt(_indexA).x + _platformArray[_platformArray.length - 1].getChildAt(_indexA).width * 0.5;   
     _coinArray.push(_coin); 
    } 
} 

어떻게 이러한 아이들을 제거 할 수 있습니까? var _obstacle : MC_obstacle = new MC_obstacle(); ? 도움이 될 것입니다! 미리 감사드립니다

참고 :이 var _obstacle 걸릴 경우 : MC_obstacle = new MC_obstacle(); For 루프의 외부 나는 dissapearing 장애물 이미지를 얻을 더블은

답변

1
_platformArray[_platformArray.length - 1].removeChildAt(0) 

또는

for(var a:int = 0;a<_platformArray[_platformArray.length - 1].numChildren;a++){ 
_platformArray[_platformArray.length - 1].removeChildAt(a) 
} 

장애물을 쌓아 또는 u가 FP 11 +

_platformArray[_platformArray.length - 1].removeChildren() 
+0

옵션의 완벽한 세트를 사용하는 경우! 고맙습니다! 나는 지금 많은 것을 배웠다. – diskrim

+0

np, 다행히 도왔습니다. – Urosan