Category Archives: Programming

Popping a Scene without destroying it; Things I didn’t know about Cocos2d-x, but I probably could have read in the docs somewhere #4

If you have the same Scene on the Director’s Scene stack, either by runWithScene or with pushScene, if you pop one off, it’ll call release on it, and effectively destroy it, making any further operations on the Scene impossible.

To resolve this, you need to call retain() on the scene, to tell cocos that somewhere else is using the scene.

Only one Action can run per Node; Things I didn’t know about Cocos2d-x, but I probably could have read in the docs somewhere #1

If you run an Effect, by creating a NodeGrid, and then adding a sprite or something to it, and then each frame, you keep calling runAction on it with a new Effect, it’ll never start, because each action is constantly getting replaced.

To solve this, I added a boolean flag on the object to see if an effect was running or not, and then only ran the effect if the flag was false.