views:

35

answers:

1

I'm creating a map in flash and I would like to have a smooth movement similar to this: http://www.conceptm.nl/

I have made a start but I'm having trouble taking it to the next stage.

My code currently throws the movieclip after the mouse is release but there is no easing while the mouse button is down.

Any tips on how I would achieve this?

Here is my current code:

// Vars
var previousPostionX:Number;
var previousPostionY:Number;
var throwSpeedX:Number;
var throwSpeedY:Number;
var isItDown:Boolean;

// Event Listeners
addEventListener(MouseEvent.MOUSE_DOWN, clicked);
addEventListener(MouseEvent.MOUSE_UP, released);

// Event Handlers
function clicked(theEvent:Event) {
isItDown =true;
addEventListener(Event.ENTER_FRAME, updateView);
}

function released(theEvent:Event) {
    isItDown =false;
}

function updateView(theEvent:Event) {
    if (isItDown==true){
        throwSpeedX =  mouseX - previousPostionX;
        throwSpeedY =  mouseY - previousPostionY;
        mcTestMovieClip.x = mouseX;
        mcTestMovieClip.y = mouseY;
    }
    else{
    mcTestMovieClip.x += throwSpeedX;
    mcTestMovieClip.y += throwSpeedY;
    throwSpeedX *=0.9;
    throwSpeedY *=0.9;
    }
    previousPostionX= mcTestMovieClip.x;
    previousPostionY= mcTestMovieClip.y;
}
+1  A: 

I would suggest using acceleration instead of speed. You'd need at least three points to get acceleration though. You could add some friction to make your object seem like it has more weight.

I haven't used this part of the TweenLite library before, but overall this library is incredible and it might help you out.

http://www.greensock.com/as/docs/tween/com/greensock/plugins/Physics2DPlugin.html

update: Sorry, looks like this plugin is part of the paid club greensock membership.

Sandro