如何抵消createjs按钮帮助'打地区?

时间:2016-02-03 19:19:27

标签: javascript button html5-canvas createjs

我使用按钮助手来点击显示框和文本区域。如果你用鼠标悬停在盒子上,只有大约2/3的盒子是可点击的。

并且允许选定区域位于右侧框的外部。如何正确设置可点击区域?只是盒子可以点击

Game Link to see example - 灰色方向框位于链接的第二页。

        self.stage.addChild(titleText);
        var directionsbox = new createjs.Container();
        displaybox = new createjs.Shape();
        displaybox.graphics.beginFill("gray").drawRoundRect(0, 0, 550, 350, 8);
        displaybox.name = "DirectionsBox";
        displaybox.x = 125;
        displaybox.y = 120;

        var label = new createjs.Text("\n" + gameData.Description + "\n\n\nDirections  \n \nThere are 3 levels to complete.  \nEach level gets a bit faster.  \nYour high sccore will automataly be submited to the Arcade. \n\n\nClick here to start sorting.", "bold 20px Arial", "#FFFFFF");
        label.textAlign = "center";
        label.lineWidth = 550;
        label.y = displaybox.y;
        label.x = displaybox.x + 275

        directionsbox.addChild(displaybox, label);
        self.stage.addChild(directionsbox);

        var helper = new createjs.ButtonHelper(displaybox, "out", "over", "down", false, displaybox, "hit");
        helper.y = displaybox.y;
        helper.x = displaybox.x + 275
        displaybox.addEventListener("click", handleClick);
        function handleClick(event) {
            createjs.Sound.play("click");
            self.stage.removeChild(directionsbox);
            StartInteraction();
        }

1 个答案:

答案 0 :(得分:1)

hitArea的问题在于您正在使用您的实例,因为它明确地使用了自己的hitArea。 HitAreas旨在自动定位到他们的内容。由于您的IndexOutOfBoundsException已设置了x / y,因此已添加到hitArea的位置,该位置已相对于您的可见displayBox定位。

在您的示例中,您只需将ButtonHelper的displaybox参数设置为hitArea即可。这将使ButtonHelper使用实际可见内容作为hitArea,它工作正常。如果要使用外部实例,可以克隆DisplayBox,将其x / y设置为0,然后使用它。

null

希望有所帮助。