簡體   English   中英

如何在拖動時調整圖像大小?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM