Wednesday, 2 April 2014

Working Processes: Creating the Game - Scripting the panning

Thanks to the feedback I received from Daniel today, I got to work creating the panning feature users would use to move through my piece.

I ended up creating the following script:

stage.addEventListener(Event.ENTER_FRAME, mousePlacementX);
function mousePlacementX(event:Event) {
    if (mouseX <50) {
        if (roomView.x<=110) {
            moveLeft();
        }
    } else if (mouseX >950) {
        if (roomView.x>=-600.25) {
            moveRight();
        }
    }
}

function moveLeft():void {
    roomView.x+=20;
    trace(roomView.x);
    if(alertArrow2.visible){
        alertArrow2.visible=false;
    }
}
function moveRight():void {
    roomView.x-=20;
    trace(roomView.x);
    if(alertArrow.visible){
        alertArrow.visible=false;
    }
}

When creating the script, I found it was best to add traces in. This way I would be able to tell and in turn script the exact number I would like the movieclip to stop moving left or right.

I am very pleased with the result of this script.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.