I've got a simple script that creates objects and I would like those objects to be destroyed when clicked on with the mouse. I'm not that great with javascript yet. I can understand the code but cannot create it.
I tried adding an event below "stage.addChild(newElement.shape);"
but this didn't work...
Any tips on how to go about deleting dynamic bodies that are clicked on would be greatly appreciated!
Thanks
Code: Select all
buttonHeart = new createjs.Bitmap("img/heart_button.png");
buttonHeart.x = 10; buttonHeart.y = 50;
buttonHeart.addEventListener("click", function () {
var newElement = addDynamicBody('heart');
newElement.shape = new createjs.Bitmap("./img/heart.png");
newElement.shape.scaleX = 2 * 30 / 50;
newElement.shape.scaleY = 2 * 30 / 50;
stage.addChild(newElement.shape);
});
I tried adding an event below "stage.addChild(newElement.shape);"
Code: Select all
newElement.addEventListener("click", function () {
DestroyBody(newElement);
});
but this didn't work...
Any tips on how to go about deleting dynamic bodies that are clicked on would be greatly appreciated!
Thanks