hmmm interesting...
ball.checkBricks is a method of the ball object? So it may be a
scoping issue? If you're calling the checkBricks function from within
the ball object you'd need to do a call on this.hitTest(brick0_0),
rather than ball.hitTest(...). Try that first.
Just a general comment, eval is not widely used any more, although it
will work when it's on the right hand side of an equation, it won't on
the left. But you can use the square bracket notation :
_root["brick"+row+"_"+col];
Oh and of course it's not good practice to refer to _root, but we'll
take that on another time ;-)
hope this helps
Seb Lee-Delisle
http://sebleedelisle.com
On 31/10/06, Martin Scott Goldberg <[EMAIL PROTECTED]> wrote:
Working on another side project (Breakout clone), and am having an
interesting problem with hitDetect. The paddle and ball are detecting
hits with each other just fine, but the same code isn't working for the
bricks. The ball, paddle, and brick are all attached dynamically.
Here's the initialize code for the player and paddle:
_root.attachMovie("ball", "ball", 2);
ball._x = 275;
ball._y = 200;
_root.attachMovie("paddle", "player", 1);
player._x = 200;
player._y = 362;
Here's the code for the bricks:
yPos = 150.8;
xPos = 138.3;
zBuff = 3;
for (col = 0; col < 14; col++)
{
for (row = 0; row < 8; row++)
{
_root.attachMovie("brick", "brick" + row + "_" +
col, zBuff);
currentBrick = eval("brick" + row + "_" + col);
currentBrick._x = xPos;
currentBrick._y = yPos;
yPos = yPos - 8;
zBuff++;
}
xPos = xPos + 21;
yPos = 150.8;
}
The hit test routine for the ball/paddle (which works) uses:
if (ball.hitTest(player))
etc. etc.
The routine for the ball/brick (which is not working) is a sample one I
have for just one brick test right now:
ball.checkBricks()
{
if (ball.hitTest(_root.brick0_0))
{
_root.brick0_0.removeMovieClip();
}
}
I've tested the _root.brick0_0.removeMovieClip() line on its own, and that
works fine (it removes the lower left brick in question perfectly). Its
the hitTest that's not working. I tried setting it to
this.hitTest(_root.brick0_0) and that incorrectly returns true all
the time (even when the program first starts up and the ball hasn't
started moving yet).
Am I approaching something wrong with levels? I know I have the brick
name right (brick0_0), and hitTest is working fine for the Paddle and Ball
itself. Really confusing.
Marty
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com