【发布时间】:2015-12-19 09:37:03
【问题描述】:
我想使用画架在画布上的矩形内移动我的文本对象。我希望文本对象在触及矩形边界后立即停止移动。我怎样才能在easeljs中做到这一点?还是使用另一个框架更好?还是分层画布?
我在画布上的矩形边界是这样的:
var textBoundary = new createjs.Shape();
textBoundary.graphics.beginStroke("#999");
textBoundary.graphics.setStrokeStyle(1);
textBoundary.snapToPixel = true;
textBoundary.graphics.drawRect(82, 130, 149, 240);
textBoundary.setBounds(82, 130, 149, 240);
stage.addChild(textBoundary);
stage.update();
到目前为止,我的拖动代码看起来像这样:
var textFront = new createjs.Text();
var t = document.getElementById("TextInput1").value;
textFront.text = t;
var draggerFront = new createjs.Container();
draggerFront.x = 160;
draggerFront.y = 130;
draggerFront.addChild(textVorne,tb);
stage.addChild(draggerFront);
draggerFront.on("pressmove",function(evt) {
evt.currentTarget.x = evt.stageX ; // here I have no idea what to
evt.currentTarget.y = evt.stageY ; // do when the dragger reaches
draggerFront.mouseMoveOutside = false; // boundary
stage.update();
});
stage.update();
提前感谢任何帮助或正确方向的指示。
【问题讨论】:
标签: drag-and-drop html5-canvas easeljs createjs