Skip to main content
Participating Frequently
November 9, 2012
Question

Ho do I do collision detection inside a movieclip?

  • November 9, 2012
  • 1 reply
  • 771 views

I have a maze game. The maze is composed of movieclips of horizontal and vertical walls arranged to make a small 5x3 maze. The code to construct the maze is in a sub-class and is called from the main class as a movieclip

                    var maze:Maze;                   

                    maze = new Maze();

                    addChild(maze);

The only trouble is I can't now do collision detection for the walls as they are now one movieclip and my player is inside of it so collision detection using hitTestObject will go off all the time. Ideally I'd like to keep the maze building code in a seperate .as file for neatness so if I can avoid putting all that code back into the main .as file then that would be preferable.

Can anyone help me?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
November 9, 2012

use a hittestobject between the player child and the wall children.

helen269Author
Participating Frequently
November 9, 2012

There are 0-37 horizontal walls in an array in the sub-class. I tried to do this:

for (h=0;h<38;h++)

                {

                 if (player1.hitTestObject (hwall )) trace ("Contact!");

                }

but got an "Access of undefined property hwall" error. The hwall array is in the sub-class but the main class can't see it. :-(

kglad
Community Expert
Community Expert
November 9, 2012

then you have no array named hwall in the scope of the code you showed.

is that code on the timeline of your walls and player parent?