0

私は小さなゲームを作っています。このゲーム内で、一定時間後にレベルを変更します。ランナーなので、100pxごとにプラットフォームセクションを作成し、各プラットフォームにバナー、コイン、または障害物を飛び越えるチャンスがあります。これらは for ループで作成されます。私の問題は、レベルを切り替えるときであり、ステージに障害物がある場合は子を削除したいのですが、var は if ステートメントにしか存在しないため、単に _obstacle.removeCild() を実行できません。レベル変更機能。以下のコード:

//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ループの外側で、障害物の画像が消え、障害物が2重に積み上げられます

4

1 に答える 1

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)
}

またはfp 11+を使用している場合

_platformArray[_platformArray.length - 1].removeChildren()
于 2013-04-10T09:29:56.190 に答える