当我在动作脚本3中调整按钮大小时,命中框会更改为文本,而不是我的作业示例中的方块:
http://www.datafilehost.com/download-5ff20e2c.html
视频说明问题:http://sdrv.ms/YcnjYV
以下是代码:
import flash.events.MouseEvent;
trace("Stage(X,Y):" + stage.stageWidth + "X" + stage.stageHeight);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousePosition);
clickMe.addEventListener(MouseEvent.CLICK, handleClicks);
function mousePosition(event:MouseEvent) {
if(clickMe.mouseX >= 0 && clickMe.mouseX <= clickMe.width && clickMe.mouseY >= 0 && clickMe.mouseY <= clickMe.height)
{
do
{
var newX = Math.floor(Math.random()*stage.stageWidth);
var newY = Math.floor(Math.random()*stage.stageHeight)
}while(newX >= stage.stageWidth - clickMe.width || newY >= stage.stageHeight - clickMe.height)
clickMe.x = newX;
clickMe.y = newY;
if(clickMe.width > 50)
{
clickMe.width=clickMe.width - 5;
clickMe.height = clickMe.width - 5;
}
}
}
function handleClicks(event:MouseEvent)
{
trace("Button Clicked!");
}
如何在调整对象大小时让hitbox保持不变?
答案 0 :(得分:1)
这似乎是一种更好,更清晰的方法(假设您将clickMe剪辑移动到随机位置并将其缩小5px)
import flash.events.MouseEvent;
clickMe.addEventListener(MouseEvent.ROLL_OVER, moveSquare);
function moveSquare(e:MouseEvent):void
{
var newX = Math.floor(Math.random()*stage.stageWidth);
var newY = Math.floor(Math.random()*stage.stageHeight);
clickMe.x = newX;
clickMe.y = newY;
clickMe.width = clickMe.width - 5;
clickMe.height = clickMe.height - 5;
}
答案 1 :(得分:1)
更改按钮大小会影响其中的mouseX / mouseY值。因此,不要依赖它,只需使用基于按钮位置和大小的检查。
if(mouseX >= clickMe.x && mouseX <= clickMe.x+clickMe.width && mouseY >= clickMe.y && mouseY <= clickMe.y+clickMe.height)