ragnarok Posted January 5, 2014 Share Posted January 5, 2014 (edited) {EDIT: Kinda wrong title, I think it's got more to do with the group, rather than the single sprite} Hello everybody,for my game project I'm working on a little level editor. I plan to have a "hand drawn" map and want to work with definable areas for borders (area: Wall, you shall not pass), special effects (area: fire, take damage; area: snow, play diffrenet sound for steps) and so on. For debugging/editing- purposes, I draw the polygons in the render-stage and add small sprites to make the corners dragable (and a center-point to drag the whole area at once). This kinda works. However removing the dragable sprites (which get's "necessarry" when when ending editing). An easy way to do this is to call group.destroy() but while this works, I get a lot of errors and the mouse input stops working. This tells me I should remove some event-listeners first: Uncaught TypeError: Cannot read property 'visible' of null VM3275 phaser.js:12405 Object.defineProperty.getVM3275 phaser.js:12405 Phaser.InputHandler.checkPointerOverVM3275 phaser.js:16750 Phaser.Pointer.moveVM3275 phaser.js:15586 Phaser.Mouse.onMouseMoveVM3275 phaser.js:14929 _onMouseMoveVM3275 phaser.js:14858 The question is: Where/How? The sprites are in a Phaser group which is stored in my level data:function areasAddHandles(areaNr){ var sprite, group=game.add.group(); group.areaNr=areaNr; for(var j=0,len=this.data.areas[areaNr].polygon.points.length-1;j<=len;j++){ sprite=group.create(Level.data.areas[areaNr].polygon.points[j].x-4, Level.data.areas[areaNr].polygon.points[j].y-4, 'dot'); sprite.inputEnabled =true; sprite.input.enableDrag(true); sprite.input.useHandCursor=true; sprite.vertexId=j; sprite.events.onDragStop.add(vertexListener, sprite.game); } Level.debug.handlers.push({corners:group});}function endAreaDebug(areaId){ Level.debug.handlers[areaId].corners.destroy();}Just calling the group to destroy itself (by endAreaDebug), gives me said errors and the mouse stops working. Anybody got an idea? EDIT:I tried:Level.debug.handlers[0].corners.callAll('destroy')andLevel.debug.handlers[0].corners.forEach(function(itm){itm.destroy();})Both delete some of the handlers but not all and give me: TypeError: Cannot read property 'destroy' of null The following works without errors, until the point where I destroy the rest of the group: for (var i=0, j=Level.debug.handlers[areaId].corners.countliving(); i<j;i++) {Level.debug.handlers[areaId].corners.getAt(0).destroy();}///errors follow after this:Level.debug.handlers[areaId].corners.destroy() Edited January 5, 2014 by ragnarok Link to comment Share on other sites More sharing options...
rich Posted January 5, 2014 Share Posted January 5, 2014 Group.destroy in 1.1.4 has the ability to call destroy on all children, which should resolve this issue I believe. Also tidied up the input handler a little bit. Might be worth checking against that build. It goes live next week anyway though so not long to wait if you'd prefer for it to hit master first. Link to comment Share on other sites More sharing options...
ragnarok Posted January 5, 2014 Author Share Posted January 5, 2014 I'll wait for this. There's still enough other things to do (like getting the enemy AI to work or figuring finally out how to get github working for me ) Link to comment Share on other sites More sharing options...
Recommended Posts