dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Scroller momentum?

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    211

    Scroller momentum?

    I am attempting to make a scroller that scrolls a long image along an x-axis and a few other elements. The problem I am having is that I want to add momentum to the image that scrolls and I am not sure how to go about doing this... can someone point me in the right direction? Here is my actionscript so far:

    Code:
    main.navigation.dragbar.onPress = function(){
    	
    	this.startDrag(false, -80, 0, 285, 0);
    	
    	moveBG();
    	
    	
    }
    
    main.navigation.dragbar.onRelease = function(){
    	
    	this.stopDrag();
    	
    }
    
    function moveBG(){
    	
    	
    	main.bg.onEnterFrame = function(){
    		
    		navigationX = main.navigation.dragbar._x * 4.25;
    		
    		if(main.navigation.dragbar._x < 1){}else{
    		
    		main.bg._x = (-main.navigation.dragbar._x) * 4.25};
    		
    		}
    	
    	}
    }
    -FRIG-5
    Das Konzept Design
    www.daskonzept.com

  2. #2
    Senior Member
    Join Date
    Jul 2005
    Posts
    165
    run a search on easing functions. I'm sure you'll find some here.
    the point is to set a final value according to the location of your drag handle, but only move a part of the way on each frame.
    Code:
    finalLoc = (-main.navigation.dragbar._x) * 4.25};
    main.bg._x = (main.bg._x - finalLoc) / 5;
    I might have a mistake with the minus-plus signs, and you have to kill the onEnterFrame and fix location when your'e close enough the end-point, you'll never get to the exact location like this. (if every day you walk half the distance you have left, on the first day your'e at half way, of the second your'e at 3/4, on the third 7/8, etc).

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    211
    that's perfect thanks. I had always used tweening classes or fusekit so I have never had to manually do easing, but it is pretty simple.

    Another thing I am trying to do is add some "weight" to the dragbar, so when you drag it it feels like you are actually pulling something heavy. Any chance you might know a little bit about how to do this as well?
    -FRIG-5
    Das Konzept Design
    www.daskonzept.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center