A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Optimise Scroller?

  1. #1
    Senior Member
    Join Date
    Jun 2004
    Posts
    209

    Optimise Scroller?

    Ive used this scroller, who I cant find the author of still (to credit) Ive altered it a tiny bit, removed some stuff from original but Im not an expert at this complex scrolling stuff. Can anyone alter it to make it run better? The 12 and 5 are the lowest movement amounts I can use.

    I did ask about using math.round on this forum before but I couldnt get that to work. So if anyone thinks math round can work where do I need to exactly put it? I have heard it wont help. So anything else? Just checking, I realise there probably isnt.

    Code:
    var paused = false;										// paused variable, set to true to turn off scroller
    var active;
    
    userScroller = function (wc) {							// Creates function moveIt, do the following
    	
    	wc.imageStartX = 0;									// Where to start on the x axis, I tried changing this but it let to poor performance, so I just moved the actual mc on stage, which worked better.
    	wc.imageEndX = -wc._width + Stage.width;			// end of the image is the width, + stage width
    	wc.StartMouseX = 0;									// This seems to be where the mc will first scroll to, and relate to how far left and right you can move as it slows down. Best to keep at 0 I found
    	wc.EndMouseX = Stage.width;							// The end mouse is equal to the stage width size
    	wc.MouseRangeX = wc.EndMouseX - wc.StartMouseX;		// A calculation that says mouse range is end mousex, = start mouse
    	wc.PanRangeX = wc.imageEndX - wc.imageStartX;		// Panrange is the end of image - image start. How far to move image
    
    	wc.imageStartY = 0;									// where to start the image on the y Axis, at 0
    	wc.imageEndY = -wc._height + Stage.height;			// the height plus the actual stage height, so it can know the end I think
    	wc.StartMouseY = 0;									// start position. Again found best to have at zero and move mc instead
    	wc.EndMouseY = Stage.height;						// end mouse is stage height value
    	wc.MouseRangeY = wc.EndMouseY - wc.StartMouseY;		// The mouse range y is endmouse y minus the start mouse y
    	wc.PanRangeY = wc.imageEndY - wc.imageStartY;		// The pan range is image end - image start. keeps the scrolling to the image only
    
    	wc.onEnterFrame = function() {														// Checks all the time using onenterframe, uses cpu power but I have tested on lower end machine and works fine.
    		if (!paused) {																	// If it is paused basically it will stop, after this code seems to be how it actually moves rather than how to pause
    			wc.rX = (_root._xmouse - wc.StartMouseX) / wc.MouseRangeX;					// Complicated sum to determine where the mouse is on the x axis I think
    			wc.rX = Math.max(0, Math.min(1, wc.rX));									// Math flash sum, which enables the movement with math max, 0 seems to be the location of image, changing it results in scrolling going off canvas
    			wc._x += ((wc.rX * wc.PanRangeX + wc.imageStartX) - wc._x) / 12;//was 30	// The number is the speed which it scrolls at on the x axis
    
    			wc.rY = (_root._ymouse - wc.StartMouseY) / wc.MouseRangeY;					// Get the y mouse value, minus the start mouse, by the mouse range
    			wc.rY = Math.max(0, Math.min(1, wc.rY));									// Working out positioning and movement using math sums from flash
    			wc._y += ((wc.rY * wc.PanRangeY + wc.imageStartY) - wc._y) / 5;			// The pan range plus the image image start on the y axis. by 30. The number is the speed it can scroll on the y axis. Higher the slower. (uses lot of cpu if its higher)
    		}																				// end of script
    
    	};																					// end of function
    };																						// end script
    
    // Says in script make sure the registration point is in top corner
    
    userScroller(mainContent);		// call move it for main content
    userScroller(closeObjects);		// call move it for close objects
    Last edited by asmallmonkeyman; 02-13-2008 at 03:47 PM.

  2. #2
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    What FPS are you running your movie at? That is going to be the biggest factor in how smooth 'enterFrame' events move things.

    I would suggest 60+ for something like this.

  3. #3
    Senior Member
    Join Date
    Jun 2004
    Posts
    209
    I cant really change the fps as the animations will all need redoing, some are not script based. Its on 24fps. I have heard the browsers knock it down anyway so it wouldnt be able to do 60 etc.

    It works ok as it is, just not perfect. Ill try the fps again, I did try it before. I want it to work on at least a 1ghz pc, I guess it would.

    More info about flash player 9 and browsers would be useful. The info I got was from flash player 7 that browsers down fps etc
    Last edited by asmallmonkeyman; 02-13-2008 at 06:29 PM.

  4. #4
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    With the latest flash player, browsers should not mess with fps anymore, or at least that is my understanding at least from some discussion about this in the games forum.

    Round would be used if you were having a problem with it 'jittering' and not coming to rest.

    I don't know if anything can be done to make the movement smoother without making the movie run at higher fps. Hopefully someone else will have a suggestion.

  5. #5
    Senior Member
    Join Date
    Jun 2004
    Posts
    209
    It does jitter about a it yes. A sort of wobbly look at times, but it was very severe before now its not too bad. I just tried it on 60fps and it works almost perfectly. Id only have to change one simple animation that isnt scripted, but Im wondering what sort of computer it would need min to run? I guess Ill have to test it out on some pcs.

    Im not sure where to put any sort of math round in. I tried it near the math max but i dont know the syntax of how to put it in really, so it wouldnt work with round in.

    *Ive just tried adding math round, but i dont think its in the right place. Not sure if its working or not.

    Code:
    wc.onEnterFrame = function() {														// Checks all the time using onenterframe, uses cpu power but I have tested on lower end machine and works fine.
    		if (!paused) {																	// If it is paused basically it will stop, after this code seems to be how it actually moves rather than how to pause
    			wc.rX = (_root._xmouse - wc.StartMouseX) / wc.MouseRangeX;					// Complicated sum to determine where the mouse is on the x axis I think
    			wc.rX = Math.max(0, Math.min(1, wc.rX), Math.round());									// Math flash sum, which enables the movement with math max, 0 seems to be the location of image, changing it results in scrolling going off canvas
    			wc._x += ((wc.rX * wc.PanRangeX + wc.imageStartX) - wc._x) / 16;	// 12	// The number is the speed which it scrolls at on the x axis
    
    			wc.rY = (_root._ymouse - wc.StartMouseY) / wc.MouseRangeY;					// Get the y mouse value, minus the start mouse, by the mouse range
    			wc.rY = Math.max(0, Math.min(1, wc.rY), Math.round());									// Working out positioning and movement using math sums from flash
    			wc._y += ((wc.rY * wc.PanRangeY + wc.imageStartY) - wc._y) / 8;	//5		// The pan range plus the image image start on the y axis. by 30. The number is the speed it can scroll on the y axis. Higher the slower. (uses lot of cpu if its higher)
    		}																				// end of script
    
    	};																					// end of function
    };
    Last edited by asmallmonkeyman; 02-13-2008 at 06:47 PM.

  6. #6
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    What I meant by jittery was if the image would not settle down and stop. Like if you kept the mouse still and the image still kept moving just a little bit permanently.

    I can't get your original code to do this in my testing. Since it seems to work good for me at 60 fps, I don't really know how to optimize it.

  7. #7
    Senior Member
    Join Date
    Jun 2004
    Posts
    209
    Thanks very much for your help. Ive lowered the movement to as smooth as possible and used 40fps. I also lowered my image as low as possible, although its still large.

    Cheers

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