Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jameslavis

Blitmask help, just turning off and on

Recommended Posts

Hey folks,

I have the blitmask disabled so I can have interactivity in my vertical scroller. But after scouring the forums I found a post that mentions you can turn it on and off by enabling and disabling it based upon the mouse down vs. mouse up. I'm using base code generated by a greensock post to make the vertical scroll using THROWPROPS.  Can anyone help a newbie coder enable and disable blitmask as I definitely see the benefits. My code is below and the page I'm referencing is here: 

 

https://greensock.com/blitmask

 

 

var bounds:Rectangle = new Rectangle(0, 0, 1280.15, 720);
var blitMask:BlitMask = new BlitMask(main, 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(main);
y1 = y2 = main.y;
yOffset = this.mouseY - main.y;
yOverlap = Math.max(0, main.height - bounds.height);
t1 = t2 = getTimer();
main.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
main.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
 
function mouseMoveHandler(event:MouseEvent):void {
var y:Number = this.mouseY - yOffset;
//if main's position exceeds the bounds, make it drag only half as far with each mouse movement (like iPhone/iPad behavior)
if (y > bounds.top) {
main.y = (y + bounds.top) * 0.5;
} else if (y < bounds.top - yOverlap) {
main.y = (y + bounds.top - yOverlap) * 0.5;
} else {
main.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 = main.y;
t1 = t;
}
event.updateAfterEvent();
}
 
function mouseUpHandler(event:MouseEvent):void {
main.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
main.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
var time:Number = (getTimer() - t2) / 1000;
var yVelocity:Number = (main.y - y2) / time;
ThrowPropsPlugin.to(main, {throwProps:{
y:{velocity:yVelocity, max:bounds.top, min:bounds.top - yOverlap, resistance:50}
}, onUpdate:blitMask.update, ease:Strong.easeOut
}, 2, 0.3, 0.5);
}
 
function OFbandSEVENsimbutton(e: MouseEvent): void
{
main.OFbandSEVEN.gotoAndStop(2);
}
function CFbandSEVENsimbutton(e: MouseEvent): void
{
main.CFbandSEVEN.gotoAndStop(2);
}
Link to comment
Share on other sites

I see how to do it, but it's the syntax of where. I was doing the disable in the mouseup, and the enable in the mouse down. I didn't notice a different with the blitmask.. so it's gotta be how and where I'm putting the command.

Link to comment
Share on other sites

hmm, I'm getting confused. does this issue differ from your other post? http://greensock.com/forums/topic/11408-help-with-click-vs-drag/

 

I think if you uploaded a super simple file that we can look at it would help. I really can't read all that code and figure it out.

Just zip and upload an fla that only has enough code and assets to clearly illustrate your issue (preferably not your production files with lots of artwork).

Pls don't upload your members-only files. You can add an attachment using the "more reply options" button.

 

thx

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.
×