![](/img/trans.png)
[英]Issue with Flash AS3 Player movieclip and creating an instance
[英]How to make a MovieClip stick to the Flash player edge?
我已經開始使用ActionScript編寫代碼,並嘗試執行此程序。 它在舞台上繪制一個形狀,您可以使用箭頭鍵移動它。 我添加了一個“邊緣粘貼”功能,將一半的形狀粘在邊緣上。 這是我的代碼:
function freemove(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
testing.y -= 5;
if(testing.y < stage.width)
{
testing.y = 0;
}
break;
}
case Keyboard.DOWN:
{
testing.y += 5;
// FOR BOTTOM EDGE.
break;
}
case Keyboard.LEFT:
{
testing.x -= 5;
if(testing.x < stage.height)
{
testing.x = 0;
}
break;
}
case Keyboard.RIGHT:
{
testing.x += 5;
// FOR RIGHT EDGE.
break;
}
}
}
問題是:它只適用於左邊和上邊。 如何使其適用於底部和右邊緣? 謝謝! =)
// FOR BOTTOM EDGE.
if (shape.y + shape.height > stage.stageHeight)
// FOR RIGHT EDGE.
if (shape.x + shape.width > stage.stageWidth)
此外,您可能會在LEFT和RIGHT處理程序中混淆寬度和高度(為什么y
與寬度比較, x
與高度比較?)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.