Jump to content
GreenSock

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

Blitmask blues

Recommended Posts

Hi there,

 

I'm stumped, and it's probably because I've been up all night with this code.. After staring at it and tinkering with it, borrowiing bits from other snippets and trying various combinations for so long it all seems like an ugly, jumbled mess to me now and I can no longer tell up from down. There's no denying it anymore, I need help. 

There's a bug in here that I can't pin down. At first it would seem everything is normal, but then you realize there is something gravely wrong with how the overlap or the offset is being massacred on mouseDown. Or mouseMove. I've given up, any help would be really appreciated. Ive also enclosed my practice fla.

 

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(100, 100, 1280, 600);




var blitMask: BlitMask = new BlitMask(mc, bounds.x, bounds.y, bounds.width, bounds.height, true, false, 0, true);
TweenLite.delayedCall(0.1, blitMask.update, [null, true]); 
blitMask.bitmapMode = false;


var t1: uint, t2: uint, y1: Number, y2: Number, x1: Number, x2: Number, xOverlap: Number, xOffset: Number, yOverlap: Number, yOffset: Number;
var isMoving: Boolean = false;
var isCatched: Boolean = false;
blitMask.stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);


function mouseDownHandler(event: MouseEvent): void {
TweenLite.killTweensOf(mc);
blitMask.disableBitmapMode();
if (isMoving == true) {
isCatched = true;
isMoving = false;
}






x1 = x2 = mc.x;
xOffset = this.mouseX + mc.x;
xOverlap = Math.max(0.5, mc.width - bounds.width);
t1 = t2 = getTimer();
mc.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
mc.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);






}


function mouseMoveHandler(event: MouseEvent): void {
isMoving = true;
if (blitMask.bitmapMode == false) {
blitMask.enableBitmapMode();
}


var x: Number = this.mouseX - xOffset;
if (x > bounds.left) {
mc.x = (x + bounds.left) * 0.5;
} else if (x < bounds.left - xOverlap) {
mc.x = (x + bounds.left - xOverlap) * 0.5;
} else {
mc.x = x;
}
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) {
x2 = x1;
x1 = mc.x;
//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 xVelocity: Number = (mc.x - x2) / time;




ThrowPropsPlugin.to(mc, {
throwProps: {
x: {
velocity: xVelocity,


resistance: 50
}
},
onUpdate: blitMask.update,
onComplete: throwComplete,
ease: Strong.easeOut
}, 10, 0.3, 1);


}


function throwComplete() {
isMoving = false;
isCatched = false;
blitMask.disableBitmapMode();
blitMask.update(null, true);
}








mc.mc_1.addEventListener(MouseEvent.CLICK, onC);
function onC(e: MouseEvent) {
if (isMoving == false && isCatched == false) {
mc.isc.text = "Item Clicked..";
mc.mc_2.play();
} else {
mc.isc.text = "";
}
}


mc.mc_2.addEventListener(MouseEvent.CLICK, onD);
function onD(e: MouseEvent) {
if (isMoving == false && isCatched == false) {
mc.mc_2.play();
mc.isc.text = "";
} else {
// mc.isc.text = "";
}
}

 

 

It's supposed to wrap, and then on swipe just glide smoothely to a halt - doesn't matter where - ie not have any bounds. Please help?

disableBitmapTest.zip

Link to comment
Share on other sites

Sorry to hear you are having problems.

 

I looked at your file and could see that its throwing really nicely.

I think it could easily take and hour or more to try to figure out everything that is going on and I just don't have that time.

 

However, I think the biggest problems is that you are using the wrap and also disabling bitmapMode. wrap can only work when bitmapMode is true as the wrap is achieved by moving pixels around. Once bitmapMode is turned off, you are just going to see the target of your BlitMask appear wherever it is that your threw it too.

 

I wish I had a better answer or could be of more help. 

Link to comment
Share on other sites

Hi thanks for your reply,

 

so it isn't possible to have an interactive, wrapping, infinitely swipeable blitmask?

Link to comment
Share on other sites

If you want the object to be able to stop anywhere, that is correct.

 

If you had a series of panels that were all 800 wide  by 600 tall and you made sure that it always stopped on increments of 800: 0, 800, 1600, 3200, 400... Then you could pull that off.  You would just have to do some calculations to make sure that when you turn bitmapMode off that you re-position the target of the BlitMask where it should be. You could throw your target 20,000 pixels to the left and the BlitMask would display it wrapping, but when bitmapMode gets turned off the target will still be 20,000 pixels away. 

 

The main issue is that if you land where the wrap is visible there is no way to display that once you turn bitmapMode off.

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