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