-1

I'm making a maze-game. I have two objects that need to react to a hittest, my little circle (called "brikke") and the maze itself (called "form"). (I'm Norwegian)

I drew a part of the maze in flash (as one big object, connected) and converted it in to a symbol (movieclip), as for the circle.

My problem is that when I'm doing the hittest, the circle seems to react to the invisible parts of the maze, like a PNG. It reacts to the invisible "pixels" in my drawing of the maze, even tho I drew it inside flash, its not a png. But the shape of the maze is rectangular.

I also use the keypads to control the circle around the maze.

Any ideas on how I can make this work? Make the circle hittest with the shape of the maze, and only that, using the keypads to navigate the circle. So when the circle hits the maze "walls" it will bounce back to the start again.

package  {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.ui.Keyboard;
    import flash.events.KeyboardEvent;

    public class Dokument extends MovieClip {

        var startskjerm: Startskjerm=new Startskjerm(); 
        var startknapp: Startknapp=new Startknapp(); 
        var bakgrunnbane: Bakgrunnbane=new Bakgrunnbane(); 
        var brikke: Brikke=new Brikke(); 
        var bane: Bane=new Bane();
        var form: Form=new Form(); 
        var regler: Regler=new Regler(); 
        var spilleregler: Spilleregler=new Spilleregler(); 
        var tilbake: Tilbake=new Tilbake(); 

    public function Dokument() {

            addChild(startskjerm); 
            addChild(startknapp); 
            addChild(regler);

            startknapp.x= 1020;
            startknapp.y= 350;

            regler.x= 920;
            regler.y= 450;

            startknapp.addEventListener(MouseEvent.CLICK, trykket);
            regler.addEventListener(MouseEvent.CLICK, klikket); 
            stage.addEventListener(KeyboardEvent.KEY_DOWN, tastetrykk); 

            }


    public function trykket (evt:MouseEvent) {

            removeChild(startknapp); 
            removeChild(startskjerm); 
            addChild(bakgrunnbane); 
            addChild(bane);
            addChild(form); 
            addChild(brikke);

            brikke.x= 200;
            brikke.y= 95; 

            bane.x= 630;
            bane.y= 485;

            form.x= 628;
            form.y= 449;

           }



    public function klikket (evt:MouseEvent) {

            removeChild(regler); 
            removeChild(startskjerm); 
            addChild(spilleregler); 
            addChild(tilbake); 

            tilbake.x= 1100;
            tilbake.y= 850;

            tilbake.addEventListener(MouseEvent.CLICK, tilbakeklikk);

            }

    public function tilbakeklikk (evt:MouseEvent) {

            removeChild(spilleregler); 
            removeChild(tilbake); 
            addChild(startskjerm); 
            addChild(startknapp); 
            addChild(regler);

            tilbake.x= 1100;
            tilbake.y= 850;

            startknapp.x= 1020;
            startknapp.y= 350;

            regler.x= 920;
            regler.y= 450;

            tilbake.addEventListener(MouseEvent.CLICK, tilbakeklikk);

            }


    public function tastetrykk(evt:KeyboardEvent) {


            if(evt.keyCode==Keyboard.LEFT){

                brikke.x= brikke.x-8; 
            }


            if(evt.keyCode==Keyboard.RIGHT){

                brikke.x= brikke.x+8; 
            }

            if(evt.keyCode==Keyboard.UP){

                brikke.y= brikke.y-8; 
            }

            if(evt.keyCode==Keyboard.DOWN){

                brikke.y= brikke.y+8; 
            }

            if(brikke.hitTestObject(form)== true) {

                trace('truffet');
            }
        }
    }   
}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

0

Try to use hitTestPoint instead of hitTestObject.

If your 'brikke' is bigger shape you can create more points in it and then check hitTestPoint for each point. Remeber to use localToGlobal or globalToLocal to be shure that you work in the same coordinates.