Hello, I'm a bit lost on the math path.
Maybe someone can help me with this one. At first glance it seems easy but I dont know any further. uh!
Ok, what it is about:
I have a sprite that:
1. can be scaled with the mouseWheel.
2. can be paned x and y proportional to the stage.mouse and the size of the sprite. When the mouseX = 0, the sprite.x = 0, When the mouseX = stage.stageWidth, the sprite.x = sprite.width - stage.stageWidth *-1
My problem is: when I combine the to tweens, the sprite moves top-left to bottom-right and comes back.
The point on the sprite under the mouse should stay the same, though.
package {
import com.greensock.TweenLite;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class ZoomPan extends Sprite {
private var content : Sprite = new Sprite();
private var scale : Number = 6;
public function ZoomPan() {
draw(content);
addChild(content);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
stage.addEventListener(Event.ENTER_FRAME, onFrame);
}
private function onFrame(event : Event) : void {
TweenLite.to(content, .5, {scaleX:scale, scaleY:scale, y:-(content.height - stage.stageHeight ) / stage.stageHeight * stage.mouseY, x:-(content.width - stage.stageWidth ) / stage.stageWidth * stage.mouseX});
}
private function onMouseWheel(e : MouseEvent) : void {
if(MouseEvent(e).delta < 0) {
scale = content.scaleX - .3;
} else {
scale = content.scaleX + .3;
}
}
private function draw(content : Sprite) : void {
for (var i : int = 0;i < 100; i++) {
for (var j : int = 0;j < 80; j++) {
content.graphics.beginFill(((i * j) * (0xffffff / 80000)) + 0xaa0000);
content.graphics.drawRect(i * 15, j * 15, 15, 15);
content.graphics.endFill();
}
}
}
}
}
Any sugestions?
Best,
Martin