Hi,
Collision detection is achieved with the hitTest method...
this.onEnterFrame=function(){
if(mcA.hitTest(mcB)){
trace("collision");
}
}
However, the hitTest only test for the graphics bounding box so irregular shapes other than a square will create some problems. For a game with multiple enemies, it would prob be best to store the enemies in an array and use a for loop to hitTest...
myEnemies=["enemy0","enemy1","enemy2"]
Now you can employ a hitTest against a hero movieclip with something like...
this.onEnterFrame=function(){
for(i=0;i<myEnemies.length;i++){
if(heroMC.hitTest(myEnemies[i]){
trace("Collision detected");
}
}
}
As for collecting objects, you would prob use a hitTest with a custom function for either fading the alpha or toggleing the visible property of a movieclip...
Alpha fade function...
function fadeObject(fTarget){
this.onEnterFrame=function(){
fTarget._alpha -=10;
if(fTarget._alpha<=0){
delete this.onEnterFrame;
}
}
}
//Usage.....functionName(targetObject)
fadeObject(coin);
Another option is simply to toggle the coin mc's visible property...
if...hitTest...
coin._visible =false;
hope it helps
A mind once stretched by a new idea never regains its original dimensions.
- Oliver Wendell Holmes
Bookmarks