ActionScript Tweening Matrix Transform (big problem)
- by TheDarkIn1978
i'm attempting to tween the position and angle of a sprite. if i call the functions without tweening, to appear in one step, it's properly set at the correct coordinates and angle. however, tweening it makes it all go crazy.
i'm using an rotateAroundInternalPoint matrix, and assume tweening this along with coordinate positions is messing up the results.
works fine (without tweening):
public function curl():void
{
imageWidth = 400;
imageHeight = 600;
parameters.distance = 0.5;
parameters.angle = 45;
backCanvas.x = imageWidth - imageHeight * parameters.distance;
backCanvas.y = imageHeight - imageHeight * parameters.distance;
var internalPointMatrix:Matrix = backCanvas.transform.matrix;
MatrixTransformer.rotateAroundInternalPoint(internalPointMatrix, backCanvas.width * parameters.distance, 0, parameters.angle);
backCanvas.transform.matrix = internalPointMatrix;
}
doesn't work properly (with tweening):
public function curlUp():void
{
imageWidth = 400;
imageHeight = 600;
parameters.distance = 0.5;
parameters.angle = 45;
distanceTween = new Tween(parameters, "distance", None.easeNone, 0, distance, 1, true);
angleTween = new Tween(parameters, "angle", None.easeNone, 0, angle, 1, true);
angleTween.addEventListener(TweenEvent.MOTION_CHANGE, animateCurl);
}
private function animateCurl(evt:TweenEvent):void
{
backCanvas.x = imageWidth - imageHeight * parameters.distance;
backCanvas.y = imageHeight - imageHeight * parameters.distance;
var internalPointMatrix:Matrix = backCanvas.transform.matrix;
MatrixTransformer.rotateAroundInternalPoint(internalPointMatrix, backCanvas.width * parameters.distance, 0, parameters.angle - previousAngle);
backCanvas.transform.matrix = internalPointMatrix;
previousAngle = parameters.angle;
}
in order for the angle to tween properly, i had to add a variable that would track it's last angle setting and subtract it from the new one. however, i still can not get this tween to return the same end position and angle as is without tweening.
i've been stuck on this problem for a day now, so any help would be greatly appreciated.