Sprite still active after deleted O_o

Sprite still active after deleted O_o
0.0 0


Hey guys, I have an issue with sprites… I’m doing a little puzzle game that imitates the behaviour of Tetris Attack.

Here’s a quick demo: http://www.albertosm.com/mozilla/ldmoz/demo.html

If you open the web console in your browser, you’ll see that everytime you click in a panel, the console will prompt which panel are you clicking.
It will show its ID (so that it differentiates from the other panels) and the type of panel it is (the number it has on the image).
This information is unique to each panel. Each panel is stored in an Array.

What I do is generate the tileset and then manually delete a series of panels for testing purposes. I delete them by doing removeChild from lazylayer and then setting them to null (For example: array[54] = null). I also tried delete array[54].

Problem is that the mouse click still recognises an empty space as a panel, which is crazy since there’s no panel there!

As I said, I tried both “array[54] = null” and “delete array[54]” which work. But the mouse still thinks there is a sprite there.

I don’t know if I’m missing any kind of destructor method for cc.Sprite (or cc.Node)?



I the version your have online, I cant see where its removing the child? Have you updated it since posting?

Also, one other thing which may be the problem. You don’t seem to remove the touch delegate on the object

i.e This function is never called


If you click and hold the mouse while the block is falling the object that you have clicked on appears set to null in the deselect function.

Also. Why are you using the LazyLayer for things that change ? I was under the impression that the LazyLayer was a special layer and was reserved backgrounds etc and other things that don’t change during the lifetime of the game.

I think that your problems are more likely to be logic errors that issues with the actual Sprites not being removed, or if the sprites are not removed its because they cant be removed because some sort of memory or event linkage to you main code.

I like you code that allows the Panel objects to receive touches. I posted a question about this, and the response I got was that touch was not supported on Sprites and that I should process touch events on the “layer”, but your solution is much neater :wink:




Hi Roger, thanks for the reply.

I’m assuming that you can see my code (the JS files) but if not, there you go: http://www.albertosm.com/mozilla/ldmoz/src/myApp.js
At the end of the initStage function is the way I have to delete certain array elements(panels). It’s pretty straight-forward.

Now, the setUNReady function is never called (I created it on the get go) and I assume I should make use of that, since I can’t seem to find another way to “detach” the sprite from the touchDispatcher temporarily.

I’m using lazyLayer just for kicks. From what I’ve read, I don’t think I’m doing anything wrong, and it works, so… :confused:

And lastly, about the panel controls. I thought of making the layer as the “controller” like you say, but I’m working with an array. This would mean that everytime you’re touching you would have to use a FOR to locate which panel are you touching, which is kinda tedious. So I made them simpler by adding each one to the Touch Dispatcher :slight_smile:

Again thanks :slight_smile:


Hi Alberto,

Yes. I can see your code, I already download all the code and the resources, as its easy to see which files you used by looking in the cocos2d.js and resources.js files ;)
OK about LazyLayer. I’m not sure… I know it does strange things if you have more than one LazyLayer i.e in different cc.layer’s as I it doesn’t respect the layer order of the cc.layers, but apart from that it seems to work in the same way as normal layers
so I wonder why it was created.

Re: Touch dispatcher.

Yes. Its a great idea to use that. It makes the code much more modular.

Re: Problems with the code.

Even though I have all your code, I cant quite see how it works.
I presume that as “block” falls, you keep checking if it has landed on another block, and if the block it lands on is the same type, you want to remove both “blocks”??
I’m not entirely sure of the game play?

BTW. What IDE are you using. I’ve been using an evaluation version of JetBrains WebStorm, and it really good, especially if you use the firefox debugging extension as it allows you to set breakpoints in the JS from within the IDE and also has a good stack trace and variable inspection.




Whoa whoa, easy! haha!
The gameplay is still in the works. If you youtube Tetris Attack you might get an idea where this is going.

I’m only using Sublime Text for the code. I’ll have to check out WebStorm as well, that debugging extension sounds neat :stuck_out_tongue: Bad thing is that it’s shareware :confused: