Hey Smokey. I had similar issues with breakout recently. trouble is hitTest is a pretty bad way of doing it, not only do you have to chack every single tile, but there's no eal way of measuring an accurate angle for the bounce (if you have, then there is no use for hitTest in the first place).
its pretty hard to find a starting point to explain this, i took me a while to work out myself,
the replacement for hitTest is these two lines, where 'this' is referring to your ball
ActionScript Code:
var cell_x = Math.ceil((this.x-stageLeft)/blockWidth)-1;
var cell_y = Math.ceil((this.y-this.stageTop)/blockHeight)-1;
if you have laid out your blocks along a grid, then you now know which block the ball is over with two lines rather than a massive loop of hitTests.
next, you check to see if a block is there.
i do this by constructing a two dimensional array, at the same time as adding my blocks to the stage. put a variable is that says amHere = true
so you just need to say now
ActionScript Code:
if (blockArray[cell_x][cell_y].true){
this["block" + cell_x + "_" + cell_y].removeMovieClip()
blockArray[cell_x][cell_y] = false
}
hope that makes sense to you.
the next thing is to work out the angle the ball has to bounce at depending on which side of the block it has hit. I'll include the code that i used here, you would have to modify it for your own movie. but if you can make sense of it, it works a heap better than the method you are using at the moment.
ActionScript Code:
var path = this._parent.blockStore[cell_x][cell_y].path;
var ylength = (this.y-this._y);
var ymov = this.yspeed/Math.abs(this.yspeed);
var tileY = path._y+(ymov*path._height);
var pcnt = ylength/(tileY-this._y);
var ballX_pcnt = (this._x-this.x)*pcnt;
if (ballX_pcnt<0) {
if (this._x+ballX_pcnt<path._x-(path._width/2)) {
this.xspeed *= -1;
this.x += this.xspeed;
} else {
this.yspeed *= -1;
this.y += this.yspeed;
}
} else {
if (this._x+ballX_pcnt>path._x+(path._width/2)) {
this.xspeed *= -1;
this.x += this.xspeed;
} else {
this.yspeed *= -1;
this.y += this.yspeed;
}
}
if you have any questions then post them and I'll answer. Hope i havent just confused matters.