Cocos2d: creating an instance of CCRenderTexture crashes my App but can't figure out how to debug this

好久不见. 提交于 2020-01-06 08:52:13

问题


EDIT (shorter version after additional testing): I only added:

        CGSize winSize = [[CCDirector sharedDirector] winSize];
        CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];

to my BulletCache in my game project (that has a GameScene where an instance of BulletCache is added) and now the app does crash whilst trying to load the gamescene instance (before this I had no problems with this crash).

NOTE: I added a breakpoint in the init method of CCRenderTexture and it does seem to run through smoothly, it must be something after the init.

Conversely I tried the same in the init method of the GameScene and it does not crash the App. Likewise if I add it to an empty cocos2d-ios helloworld template project.

Hence in the cocos2d-ios helloworld template I did an additional testing thinking to see if there was a conflict in having a batchnode and a CCRenderTexture instance and added the following at the end of the helloworldlayer.m init method:

    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
    [frameCache addSpriteFramesWithFile:@"art1-hd.plist"];
    CCSpriteBatchNode*  spriteBatch = [CCSpriteBatchNode batchNodeWithFile:@"art1-hd.png"];
    [self addChild:spriteBatch];

    CGSize winSize = [[CCDirector sharedDirector] winSize];        
    CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];
    [self addChild:rt];

There was no crash.

I am left with not many glues on how to solve this.

EDIT: Removed original question where I mentioned a pixelperfect collision project where I had found CCRenderTexture


回答1:


Maybe the problem is simply that the original code assumes each sprite to use their own textures. Now if you have a texture atlas, each sprite renders only from a smaller area (rect) of that texture. You'll have to initialize the collision test accordingly with the sprite frame's part of the texture.

All in all, it's possible to do pixel perfect collision detection with sprite frames and texture atlas, but more complicated depending on the actual implementation of the collision test.



来源:https://stackoverflow.com/questions/12991649/cocos2d-creating-an-instance-of-ccrendertexture-crashes-my-app-but-cant-figure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!