Is there any way to display an infinite canvas with EaselJS? I have read the ways to do it with Javascript or JQuery, but is there any way to manage it with EaselJS?
Thanks!
You can drag/drop the canvas itself using JavaScript/jQuery - but there is a built-in drag-and-drop model on EaselJS content. Check out the DragAndDrop samples in the examples folder.
The main steps are:
I threw together a little spike to show this. http://jsfiddle.net/lannymcnie/jKuyy/1/
It draws a bunch of content, and then you can drag it around. The red box is what listens to the mouse events, but it then just moves a big container with all the content.
Here are the highlights:
dragBox.addEventListener("mousedown", startDrag); // Object listens to mouse press
function startDrag(event) {
// Get offset (not shown here, see fiddle)
event.addEventListener("mousemove", doDrag);
}
function doDrag(event) {
// Reposition content using event.stageX and event.stageY (the new mouse coordinates)
}
Hope it helps!
Edit: The NEXT version of EaselJS (0.7.0+, available in GitHub since August, 2013) has a brand new drag and drop model that's even easier to use. The new bubbling event model lets you just attach pressmove and pressup events on any object to get events any time someone presses an object, then makes a dragging action.
dragBox.on("pressmove", function(event) {
// Note that the `on` method automatically sets the scope to the dispatching object
// Unless you pass a scope argument.
this.x = event.stageX;
this.y = event.stageY;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With