Perfact hitTest


hello every one

 

var rightarow:boolean;

var leftarow:boolean;

var uparow:boolean;

var downarow:boolean;

var speed:int = 10;

 

 

stage.addeventlistener(keyboardevent.key_down, keypress);

stage.addeventlistener(keyboardevent.key_up, keyrelease);

stage.addeventlistener(event.enter_frame, everyframe);

 

 

 

function keypress(event:keyboardevent):void {

          if (event.keycode == keyboard.right) {

                    rightarow = true;

          }

          if (event.keycode == keyboard.left) {

                    leftarow = true;

          }

          if (event.keycode == keyboard.up) {

                    uparow = true;

          }

          if (event.keycode == keyboard.down) {

                    downarow = true;

          }

}

function keyrelease(event:keyboardevent):void {

          if (event.keycode == keyboard.right) {

                    rightarow = false;

          }

          if (event.keycode == keyboard.left) {

                    leftarow = false;

          }

          if (event.keycode == keyboard.up) {

                    uparow = false;

          }

          if (event.keycode == keyboard.down) {

                    downarow = false;

          }

}

 

 

function everyframe(event:event):void {

          if (rightarow) {

                    if(plyr2.hittestobject(r1)||plyr2.hittestobject(r2)||plyr2.hittestobject(r3)||p lyr2.hittestobject(r4)||plyr2.hittestobject(r5)||plyr2.hittestobject(r6)||plyr2.hittestobj ect(r7)||plyr2.hittestobject(r8)||plyr2.hittestobject(r9))

                    {

                              plyr2.x -= 2;

                    }

                    else

                    {

                              plyr2.x += 2;

                    }

          }

          if (leftarow) {

                    if(plyr2.hittestobject(r1)||plyr2.hittestobject(r2)||plyr2.hittestobject(r3)||p lyr2.hittestobject(r4)||plyr2.hittestobject(r5)||plyr2.hittestobject(r6)||plyr2.hittestobj ect(r7)||plyr2.hittestobject(r8)||plyr2.hittestobject(r9))

                    {

                              plyr2.x += 2;

                    }

                    else

                    {

                              plyr2.x -= 2;

                    }

          }

          if (uparow) {

                    if(plyr2.hittestobject(r1)||plyr2.hittestobject(r2)||plyr2.hittestobject(r3)||p lyr2.hittestobject(r4)||plyr2.hittestobject(r5)||plyr2.hittestobject(r6)||plyr2.hittestobj ect(r7)||plyr2.hittestobject(r8)||plyr2.hittestobject(r9))

                    {

                              plyr2.y += 2;

                    }

                    else

                    {

                              plyr2.y -= 2;

                    }

          }

          if (downarow) {

                    if(plyr2.hittestobject(r1)||plyr2.hittestobject(r2)||plyr2.hittestobject(r3)||p lyr2.hittestobject(r4)||plyr2.hittestobject(r5)||plyr2.hittestobject(r6)||plyr2.hittestobj ect(r7)||plyr2.hittestobject(r8)||plyr2.hittestobject(r9))

                    {

                              plyr2.y -= 2;

                    }

                    else

                    {

                              plyr2.y += 2;

                    }

          }

}

--------------------

i have used above code check hittest , stop object collision detect. well... working..but not in proper way....

 

when press right arrow object moves in left side....and whenever goes out of road_mc(i.e. r1, r2...r9) works fine...that moves right side...

 

 

i need solution this.. plz me.

it looks opposite of want.  ie

 

plyr.x+=2

 

should be

 

plyr.x-=2

 

etc



More discussions in ActionScript 3


adobe

Comments