samedi 4 février 2017

(Actionscript 3.0) Collision detection for dragable objects?

I am currently working on a new Flash Game that is a sliding puzzle game. However, most of the pieces are not shaped like squares as in a standard sliding puzzle game, which makes the collision detection between the pieces much harder. I decided to try to program the collision detection between the Yellow L and the White L piece, each of which are a 100X100 squares with a 50X50 square cut off of the corner. Is there anyway to give them collision detection so that they cannot overlap each other?

var YellowLClicked: Boolean=false;

addEventListener(Event.ENTER_FRAME,onEnterFrameHandler);
YellowL.addEventListener(MouseEvent.MOUSE_DOWN, dragYellowL); 
YellowL.addEventListener(MouseEvent.MOUSE_UP, DoNotdragYellowL);
YellowL.addEventListener(MouseEvent.ROLL_OUT, DoNotdragYellowL);

function dragYellowL(e:MouseEvent): void{
    YellowLClicked=true;
}
function DoNotdragYellowL(e:MouseEvent): void{
    YellowLClicked=false;
}
function onEnterFrameHandler(e:Event): void{
    if(YellowLClicked){
           YellowL.startDrag();
    } else YellowL.stopDrag();

    //Can you help with this code here?
    if(YellowL.hitTestObject(WhiteL)) trace("true"); else trace(false);

}

Aucun commentaire:

Enregistrer un commentaire