使用 Tween Class AS3 从中心点缩放 [英] Scale from center point with Tween Class AS3

查看:33
本文介绍了使用 Tween Class AS3 从中心点缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Tween 类 AS3 从其中心点缩放动态文本框.

I need to scale a dynamic text box from it's center point using Tween class AS3.

基本上,我需要在 300 毫秒左右的时间内缩小到 50%……完成后我想再次放大到 100% 并停止动画.

Basically, I need to scale down to 50% in 300ms or so... and after finish I want to scale up again to 100% and stop animation.

我尝试将中心点设置为文本框的中心,但它总是从左侧缩放.

I tried to set the center point to the center of the text box but it always scale from left.

好吧,我一直在努力学习 Tween 类的基础知识,但我相信它缺少一些好的属性和方法,例如 greensock!

Well I been trying hard to learn the basics of Tween class and I believe it's missing some good properties and methods like greensock!

谢谢.

title_txt.text = "Text";

var textScaleX:Tween;
var textScaleY:Tween;

title_txt.addEventListener(MouseEvent.MOUSE_OVER, scaleObj(1,2, 1));

function scaleObj(startUp:int, endUp:int, duration:int){
    textScaleX = new Tween(title_txt, "scaleX", Strong.easeInOut, startUp, endUp, duration, true);
    textScaleY = new Tween(title_txt, "scaleY", Strong.easeInOut, startUp, endUp, duration, true);
}

推荐答案

文本字段的起始点将始终位于左上角.但是,您可以计算左上角在比例的 50% 以及 x 和 y 位置以及 scaleX 和 scaleY 值之间的位置.

The oringin of a textfield will alwasy be in the top left corner. You could however calculate where the top left corner would be at 50% of the scale and the tween the x and y postion along with the scaleX and scaleY values.

快速计算 50% 的 x 和 y 类似于:

A quick calculation of the 50% x and y would be something like:

50% x = 100% x 位置 +(100% 文本框宽度)/4

50% x = 100% x position + (100% textfield width)/4

50% y = 100% y 位置 +(100% 文本框高度)/4

50% y = 100% y position + (100% textfield height)/4

代码中的计算如下所示:

Here is how this calculation in code would look like:

var targetScale:Number = .5;    //scale 50% but any other scale would work here as well
var targetX:Number = title_txt.x + (title_txt.width - title_txt.width * targetScale) / 2;
var targetY:Number = title_txt.y + (title_txt.height - title_txt.height * targetScale) / 2;

我使用我自己的 tween 类,所以我不确定如何使用 Adob​​e tween 类或 TweenLite 类来实现这一点,但是如果您将这些数字粘贴在任何 tween 类中,则文本字段(或任何起源于左上角)将围绕中心点缩放.

I use my own tween class so I'm not sure how to implement this with either the Adobe tween class or the TweenLite class, but if you stick these numbers in any tween class the textfield (or any object with it's origin in the top left corner for that matter) will scale around is center point.

这篇关于使用 Tween Class AS3 从中心点缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆