Jump to content

How to remove Events from sprites?


Recommended Posts

{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:


  1. Uncaught TypeError: Cannot read property 'visible' of null VM3275 phaser.js:12405
    1. Object.defineProperty.getVM3275 phaser.js:12405
    2. Phaser.InputHandler.checkPointerOverVM3275 phaser.js:16750
    3. Phaser.Pointer.moveVM3275 phaser.js:15586
    4. Phaser.Mouse.onMouseMoveVM3275 phaser.js:14929


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?




I tried:




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++) {



///errors follow after this:


Edited by ragnarok
Link to comment
Share on other sites

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


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...