【发布时间】:2015-05-13 17:32:18
【问题描述】:
我想要做的是让我的 MovieClip(比视口大)的边框不可见。就像许多应用程序一样,例如部落冲突。
这样,如果您放大、缩小或平移,您将永远看不到它下面的舞台。
如果我只是平移而不是缩放,那会很容易,因为我只需要计算我的 MC 矩形是否在我的舞台内,如果是,我会:
mc.x = 0 + mc.width / 2;
//or
mc.x = stage.StageWidth - (mc.width/2);
//or .... The same for y
现在最大的问题是当我也缩放时!每次我想出一些代码时,它都不能很好地工作。网上有很多通过GestureEvent 进行缩放的示例,但没有一个可以限制 MC,因此您看不到它下面的舞台。
谁能给我一个例子。假设舞台是 480x720,mc 是 1080x720!
你必须在始终覆盖舞台的同时进行平移和缩放,并且mc的比例将保持在1-1.5之间。
这是我当前的代码:
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_PAN, onPan);
stage.addEventListener(MouseEvent.CLICK, gotoBox);
var isInBox: Boolean = false;
table.x = 203.1;
table.y = 360;
table.scaleX = 1;
table.scaleY = 1;
var mouseTimer: Timer;
function onPan(event: TransformGestureEvent): void
{
if (!isInBox)
{
if (event.phase == GesturePhase.BEGIN)
{
stage.removeEventListener(MouseEvent.CLICK, gotoBox);
trace("noClick");
}
table.x += event.offsetX;
table.y += event.offsetY;
if (table.x > (table.width / 2))
{
table.x = table.width / 2;
}
if (table.x < stage.stageWidth - (table.width / 2))
{
table.x = stage.stageWidth - (table.width / 2)
}
if (table.y > (table.height / 2))
{
table.y = table.height / 2;
}
if (table.y < stage.stageHeight - (table.height / 2))
{
table.y = stage.stageHeight - (table.height / 2)
}
if (event.phase == GesturePhase.END)
{
if (mouseTimer !== null)
{
if (mouseTimer.running)
{
mouseTimer.stop();
mouseTimer.removeEventListener(TimerEvent.TIMER, enableClick);
}
}
mouseTimer = new Timer(250);
mouseTimer.addEventListener(TimerEvent.TIMER, enableClick);
mouseTimer.start();
trace("start");
}
}
}
function enableClick(e: TimerEvent)
{
mouseTimer.stop();
trace("stop");
mouseTimer.removeEventListener(TimerEvent.TIMER, enableClick);
stage.addEventListener(MouseEvent.CLICK, gotoBox);
trace("nowClick");
}
function gotoBox(e: MouseEvent)
{
// here it goes to another frame
}
我无法添加缩放功能,因为它完全是一场灾难;我在这个链接 FlashAndMath 中使用了类似于函数onZoom 的东西
因为我需要放大和缩小一个点,这是主要问题,因为我必须移动我的 mc 以使该点位于中心,而我必须移动它来制作我的整个 MC在一定的范围内覆盖舞台!这些运动也相互对抗。如果最后一部分不清楚,请让我解释更多:)
在得到 LDMS 的正确答案后,我更新了这个问题以避免聊天讨论:)
【问题讨论】:
-
如果您显示当前的缩放/平移代码,我将根据这些代码给您一个示例。这是很常见的情况。
-
我会把它放在这里,但在我只想说之前我在手机上问这个问题之前已经犯了一些错误,比如我没有写的“约束”这个词它必须是一个单词建议,也是以小写开头的“StageWidth”:)
-
当你说更新我不明白你的意思时,我可以编辑、发送评论并回答我的 Q,所以我做了第三个。对不起。并感谢您多次帮助我;)
-
#LDMS 它的鼠标点击
-
好的,您可能会做的是在捕获阶段收听并停止在您的子鼠标点击中传播事件。我不确定这会如何影响客人(我几乎从未使用过客人,而且我不确定取消鼠标按下事件是否会阻止客人发送。我明天会玩弄它以找出答案.
标签: actionscript-3 flash zooming gesture pan