CanvasScript3
>
Tests
> Sprite - StartDrag
Code
var stage = new Stage("canvas", 420, 500, 30); var sprite = new Sprite(); sprite.x = 50; sprite.y = 50; sprite.graphics.lineStyle(0); sprite.graphics.beginFill(0xFF0000); sprite.graphics.drawCircle(0, 0, 30); sprite.graphics.endFill(); sprite.addEventListener(MouseEvent.MOUSE_DOWN, function(e) { sprite.startDrag(); }); sprite.addEventListener(MouseEvent.MOUSE_UP, function(e) { sprite.stopDrag(); }); stage.addChild(sprite); //lock center var sprite2 = new Sprite(); sprite2.x = 50; sprite2.y = 150; sprite2.graphics.lineStyle(0); sprite2.graphics.beginFill(0x00FF00); sprite2.graphics.drawCircle(0, 0, 30); sprite2.graphics.endFill(); sprite2.addEventListener(MouseEvent.MOUSE_DOWN, function(e) { //lock center sprite2.startDrag(true); }); sprite2.addEventListener(MouseEvent.MOUSE_UP, function(e) { sprite2.stopDrag(); }); stage.addChild(sprite2); //bounds var container = new Sprite(); container.x = 50; container.y = 250; container.graphics.lineStyle(1, 0x999999); container.graphics.drawRect(0, 0, 300, 200); stage.addChild(container); var sprite3 = new Sprite(); sprite3.graphics.lineStyle(0); sprite3.graphics.beginFill(0x0000FF); sprite3.graphics.drawCircle(0, 0, 30); sprite3.graphics.endFill(); sprite3.addEventListener(MouseEvent.MOUSE_DOWN, function(e) { //limit drag area sprite3.startDrag(false, new Rectangle(0, 0, 300, 200)); }); sprite3.addEventListener(MouseEvent.MOUSE_UP, function(e) { sprite3.stopDrag(); }); container.addChild(sprite3);
Canvas
Output