Jump to content
Search Community

how to speed up the scrolling

kwontae test
Moderator Tag

Recommended Posts

Hi Greensock

 

I've made a scroll helped by  the power the ThrowPropsPlugin. I'm really satisfied with the smooth scrolling. But I'm still hungry. When I scroll down mine on my i-phone, it's not as speedy as the ios scrolling.  

If you know any way to speed up my scroll, I'd like to know the secret. 

 

Here is my code for the scroll. 

 

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.geom.Rectangle;
import flash.utils.getTimer;
import flash.events.MouseEvent;
import flash.text.*;
import flash.display.*;
TweenPlugin.activate([ThrowPropsPlugin]);




var bounds:Rectangle = new Rectangle(0,0,1024,556);
graphics.beginFill(00000000, 1);
graphics.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
graphics.endFill();

stop();
//here is where I reference the MovieClip.;
var mc:MovieClip = vertical;


var blitMask:BlitMask = new BlitMask(mc,bounds.x,bounds.y,bounds.width,bounds.height,false);
blitMask.bitmapMode = false;
var t1:uint,t2:uint,y1:Number,y2:Number,yOverlap:Number,yOffset:Number;
blitMask.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void
{
	TweenLite.killTweensOf(mc);
	y1 = y2 = mc.y;
	yOffset = this.mouseY - mc.y;
	yOverlap = Math.max(0,mc.height - bounds.height);
	t1 = t2 = getTimer();
	mc.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
	mc.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
function mouseMoveHandler(event:MouseEvent):void
{
	var y:Number = this.mouseY - yOffset;//if mc's position exceeds the bounds, make it drag only half as far with each mouse movement (like iPhone/iPad behavior)
	if (y > bounds.top)
	{
		mc.y = (y + bounds.top) * 0.5;
	}
	else if (y < bounds.top - yOverlap)
	{
		mc.y = (y + bounds.top - yOverlap) * 0.5;
	}
	else
	{
		mc.y = y;
	}
	blitMask.update();
	var t:uint = getTimer();//if the frame rate is too high, we won't be able to track the velocity as well, so only update the values 20 times per second
	if (t - t2 > 50)
	{
		y2 = y1;
		t2 = t1;
		y1 = mc.y;
		t1 = t;
	}
	event.updateAfterEvent();
}
function mouseUpHandler(event:MouseEvent):void
{
	mc.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
	mc.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
	var time:Number = (getTimer() - t2) / 1000;
	var yVelocity:Number = (mc.y - y2) / time;
	ThrowPropsPlugin.to(mc, {throwProps:{
	 y:{velocity:yVelocity, max:bounds.top, min:bounds.top - yOverlap, resistance:300}
	 }, onUpdate:blitMask.update, ease:Strong.easeOut
	}, 10, 0.3, 1);
}

 

 

Link to comment
Share on other sites

Hi Kowntae,

 

Glad that you are pleased with ThrowProps. Since you are already using a BlitMask you really have the best that we offer. I don't see anything in your code that jumps out as being cause of poor performance. I have to imagine that perhaps you have reached the limits of what AIR or the Flash display list can handle. Regardless of how optimized your code or our code is, Flash's ability to render the display is always going to be a bit of a bottleneck. 

 

I know that recent versions of AIR have gotten better and folks have had mixed results with blitting... sometimes its faster, sometimes its not. Have you tried without BlitMask? is it noticeably better or worse? Might be worth doing a quick test.

Link to comment
Share on other sites

When you say "speed up", do you mean improve performance or literally make the scrolling move with more velocity (faster)? You can increase the velocity and/or reduce the resistance value - does that help? 

 

That's right. I want my scrolling faster. 

Do you mean I can increase the maxDuration value to increase the velocity?

I guess so. Thank you very much. 

Link to comment
Share on other sites

When you say "speed up", do you mean improve performance or literally make the scrolling move with more velocity (faster)? You can increase the velocity and/or reduce the resistance value - does that help? 

 

 

Hi Kowntae,

 

Glad that you are pleased with ThrowProps. Since you are already using a BlitMask you really have the best that we offer. I don't see anything in your code that jumps out as being cause of poor performance. I have to imagine that perhaps you have reached the limits of what AIR or the Flash display list can handle. Regardless of how optimized your code or our code is, Flash's ability to render the display is always going to be a bit of a bottleneck. 

 

I know that recent versions of AIR have gotten better and folks have had mixed results with blitting... sometimes its faster, sometimes its not. Have you tried without BlitMask? is it noticeably better or worse? Might be worth doing a quick test.

Thank you very much. I will try.. 

Link to comment
Share on other sites

In your code, look at the part that says this:

 

 

y:{velocity:yVelocity, max:bounds.top, min:bounds.top - yOverlap, resistance:300}
 

 

You can just bump the yVelocity up proportionally if you want. However, that means that it won't match the movement of the user's swipe (maybe that's okay with you). For example:

 

 

y:{velocity:yVelocity * 1.5, max:bounds.top, min:bounds.top - yOverlap, resistance:300}
 

 

Multiplying it by 1.5 will make it go 50% faster. 1.2 would be 20% faster, etc. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...