[英]How to resize an image on drag?
我有一些要在拖放游戏中使用的图像。 我已经通过动作脚本代码片段完成了此工作,但是我还需要这些图像能够通过拖动底角的箭头或类似内容来调整大小。 我可以通过不包含调整大小的代码来完成拖动工作,反之亦然。
this.addEventListener(MouseEvent.MOUSE_MOVE, resize);
this.addEventListener(MouseEvent.MOUSE_UP, stopDragging, true);
this.addEventListener(MouseEvent.MOUSE_DOWN, startDragging, true);
function startDragging(E:MouseEvent):void {
resize1.startDrag();
}
function stopDragging(E:MouseEvent):void {
resize1.stopDrag();
}
function resize(E:MouseEvent):void {
item1_mc.width = resize1.x - item1_mc.x;
item1_mc.height = resize1.y - item1_mc.y;
}
有谁知道如何解决这个问题? 我知道目前我的图像调整大小代码是原始的,但可以将其更改为尽快缩放。
您必须将图像动画片段(或其他内容)分成两部分-像这样可拖动和可调整大小
myImageWidget (this is your parent movicelip)
|
|- imageMC (this will hold the image and will be the draggable object)
|- arrowMC (this is your arrow that will be OVER your image and will be used to resize)
然后在您的“ myImageWidget”中,您需要像这样的东西(摆脱所有“ this”。这没有任何意义:)
// image MC will listen for clicks and start dragging
imageMC.addEventListener(MouseEvent.MOUSE_UP, stopDragging, true);
imageMC.addEventListener(MouseEvent.MOUSE_DOWN, startDragging, true);
// arrow MC will listen for clicks and start resizing
arrowMC.addEventListener(MouseEvent.MOUSE_UP, stopResizing, true);
arrowMC.addEventListener(MouseEvent.MOUSE_DOWN, startResizing, true);
function startDragging(E:MouseEvent):void
{
startDrag();
}
function stopDragging(E:MouseEvent):void
{
stopDrag();
}
function startResizing(E:MouseEvent):void
{
addEventListener(MouseEvent.MOUSE_MOVE, resize);
}
function stopResizing(E:MouseEvent):void
{
removeEventListener(MouseEvent.MOUSE_MOVE, resize);
}
function resize(E:MouseEvent):void
{
// you will adjust this to local coordinates since you are inside of the imageWidget
width = mouseX;
height = mouseY;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.