PDA

View Full Version : Trace _name of the instance hitTest detected a collision


lupien
03-03-2008, 02:41 PM
Hi,

I`m builing a game that as a canon that shots balls to try to break walls. I have gravity on that ball and when it hits solid blocks (walls, floors) its bounces. All the block are position in the level with attachMovie. So the breakable blocks are attached inside a movieClip and the unbreakable solid blocks are in a movieClip called "terrain".

The hitTest is setup on the ball i`m shooting.
if (_root.terrain.hitTest((spot_x+_root.cannon._x), (spot_y+_root.cannon._y), true)) {
//Bounce the ball function is called
}

spot_x and spot_y are specific coordinates on the circumference of the ball. So this part work just fine.

Now here is my question and I don`t know if its even possible.
Each block within "terrain" movieClip has its own instance name. I need to find out which block the ball hit. The hitTest his checking if "terrain" is hit so how can I check what movieClip within "terrain" was it?? I`m trying to trace the instance name of the individual blocks but I just can`t figure it out.

Thanks.

ASWC
03-03-2008, 03:01 PM
for(i=0;i<numberofblocks;i++){
if (_root["terrain"+i].hitTest((spot_x+_root.cannon._x), (spot_y+_root.cannon._y), true)) {
//Bounce the ball function is called
trace(_root["terrain"+i]._name);
}

}

this would work with block instances name like terrain0, terrain1, ect...

lupien
03-03-2008, 03:11 PM
Actually i`m trying to trace movieClip name inside of terrain.
Example: Instance name = box1 which is _root.terrain.box1

ASWC
03-03-2008, 03:27 PM
you did not provide the instance name for the inside blocks so let's say it's insideblock1, insideblock2, ....ect

for(i=0;i<numberofblocks;i++){
if (_root.terrain["insideblock"+i].hitTest((spot_x+_root.cannon._x), (spot_y+_root.cannon._y), true)) {
//Bounce the ball function is called
trace(_root.terrain["insideblock"+i]._name);
}

}

lupien
03-03-2008, 03:37 PM
Thanks man.

I was just about to write the exact same thing explaining how I figured it out. That works perfect.

ASWC
03-03-2008, 03:52 PM
Cool! ;)