As the title says: Stop object from moving further when collision occurs.
Right now I’m trying to make a sliding puzzle. So far I have a block which I can click and drag around, and a few walls which are the boundaries. What I’m trying to do is make an area where the block can slide within the boundaries. So when you try to drag the block into an direction it will stop, whether you got mouse_down or mouse_up. My script so far
stop();
//Sliding Blocks
MCBlock1.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
MCBlock1.addEventListener(MouseEvent.MOUSE_UP, dropIt);
function pickUp(event:MouseEvent):void {
event.target.startDrag(true);
}
function dropIt(event:MouseEvent):void {
event.target.stopDrag()}
//Colision
MCBlock1.addEventListener(Event.ENTER_FRAME, enter_frame);
function enter_frame(event:Event):void{
if (MCBlock1.hitTestObject(MCwall1)) {
dropIt();
}
}
Anyone have any idea how to do this? Also I need to use a lot of boundaries, so if there’s a way to apply this script easily to several objects, please let me know.
Thanks in advance. ^^