
PROBLEM:
mc_1 is moved up, down, right, and left with arrow keys. It detects rectangles when hit, but it does not stop when hitting rectangles. How can I make mc_1 stop when hitting a rectangle?
HERE IS MY SCRIPT:
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveDrawing);
function moveDrawing(event:KeyboardEvent): void
{
var speed:uint=5;
switch (event.keyCode){
case Keyboard.RIGHT:
mc_1.x+=speed;
break;
case Keyboard.LEFT:
mc_1.x-=speed;
break;
case Keyboard.UP:
mc_1.y-=speed;
break;
case Keyboard.DOWN:
mc_1.y+=speed;
break;
}
}
// collision detection
mc_1.addEventListener(Event.ENTER_FRAME, rectangleHit);
function rectangleHit(event:Event): void
{
if (mc_1.hitTestObject(rectangle_mc|| rectangle_mc2)){
mc_1.stop(); //HERE IS WHERE I WANT IT STOP.
trace ("rectangle & 2 hit");
}
if (mc_1.hitTestObject(rectangle_mc1|| rectangle_mc3)){
mc_1.stop();//HERE IS WHERE I WANT IT STOP.
trace("rectangle1 &3 hit");
}
};
thanks for your help.
German
If you would like to make a comment, please fill out the form below.
Recent Comments