I'm new to EaselJS and I have a stage with bitmaps and I need to add painting functionality so shapes can be drawn on top of bitmaps.
The paint function needs stage.autoClear = false to create the shape. This code forces ALL the elements on the stage (including bitmaps) to be redrawn. But the existing bitmaps on the stage should not be redrawn.
The bitmaps are in container which is a child of stage. This is what I have (much of it from https://github.com/CreateJS/EaselJS/blob/master/examples/CurveTo.html):
function init() { canvas = document.getElementById("theCanvas"); stage = new createjs.Stage(canvas); createjs.Touch.enable(stage); stage.enableMouseOver(10); stage.mouseMoveOutside = true; stage.addChild(container); }; function initPaint() { var oldPt; var oldMidPt; var color; var stroke; stage.autoClear = false; stage.enableDOMEvents(true); createjs.Ticker.framerate = 24; stage.addEventListener("stagemousedown", handleMouseDown); stage.addEventListener("stagemouseup", handleMouseUp); stage.addChild(drawingCanvas); stage.update(); }; function handleMouseDown(event) { if(!event.primary) {return; } stage.autoClear = false; color = "#000000"; stroke = 20; oldPt = new createjs.Point(stage.mouseX, stage.mouseY); oldMidPt = oldPt.clone(); stage.addEventListener("stagemousemove", handleMouseMove); } function handleMouseMove(event) { if (!event.primary) { return; } var midPt = new createjs.Point(oldPt.x + stage.mouseX >> 1, oldPt.y + stage.mouseY >> 1); drawingCanvas.graphics.clear().setStrokeStyle(stroke, 'round', 'round').beginStroke(color).moveTo(midPt.x, midPt.y).curveTo(oldPt.x, oldPt.y, oldMidPt.x, oldMidPt.y); oldPt.x = stage.mouseX; oldPt.y = stage.mouseY; oldMidPt.x = midPt.x; oldMidPt.y = midPt.y; stage.update(); } function handleMouseUp(event) { if (!event.primary) { return; } stage.removeEventListener("stagemousemove", handleMouseMove); }
Bitmap elements have already been added to the stage. When initPaint is called with stage.autoclear = false, the bitmaps get redrawn, one on top of the other (this is evident because I have a shadow effect on the bitmaps and the shadow keeps getting darker). How do I stop the bitmap elements from getting redrawn?