문제

Okay, so let's say I have "ball" MovieClips that collide against a "wall" MovieClip.

if ( !ball.hitTestObject(wall) ) {
    // If they didn't find any obstacle keep falling.
    ball.y++;
}

Then I remove the wall, and the balls keep colliding against a wall that I cannot see. No ball moves, not the ones that were there, neither the new ones.

case Keyboard.K: removeChild(wall); break;

What am I missing or doing wrong? Thanks in advance.

도움이 되었습니까?

해결책

removeChild only removes the instance from the display list, display list has nothing to do with game logic actually... you have to either disable your movieclip with a boolean (if you later want to use it then you can enable it) or null the reference, but beware of nulling your reference, because if you try to access it after nulling, you get an error, so you might want to check that if your wall is whether null or not before checking your collision.

if(wall!=null){
    if ( !ball.hitTestObject(wall) ) {
        // If they didn't find any obstacle keep falling.
        ball.y++;
    }
}
...
case Keyboard.K:
     removeChild(wall);
     wall = null;
break;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top