Cocos2d:创建一个CCRenderTexture的实例崩溃了我的应用程序,但不知道如何调试这个 [英] Cocos2d: creating an instance of CCRenderTexture crashes my App but can't figure out how to debug this

查看:255
本文介绍了Cocos2d:创建一个CCRenderTexture的实例崩溃了我的应用程序,但不知道如何调试这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EDIT(进一步测试后的较短版本):
我只添加了

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

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



< (有一个GameScene,其中添加了BulletCache的实例),现在应用程序在尝试加载gamescene实例时崩溃(在此之前我对此崩溃没有问题)。

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).

注意:我在CCRenderTexture的init方法中添加了一个断点,它似乎顺利运行,它必须在init之后。

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.

相反,我在GameScene的init方法中也是这样,它不会使应用程序崩溃。同样,如果我将它添加到一个空的cocos2d-ios helloworld模板项目。

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.

因此在cocos2d-ios helloworld模板中,我做了一个额外的测试思考,冲突在有一个batchnode和一个CCRenderTexture实例,并添加以下在helloworldlayer.m init方法的结尾:

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];

没有崩溃。

没有多少胶水如何解决这个。

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

编辑:删除原始问题,其中我提到一个像素完美的碰撞项目,我发现了CCRenderTexture

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

推荐答案

也许问题只是原来的代码假设每个精灵使用自己的纹理。现在如果你有一个纹理图集,每个sprite只渲染从该纹理的一个较小的区域(rect)。你必须相应地用sprite框架的纹理部分来初始化碰撞测试。

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.

这篇关于Cocos2d:创建一个CCRenderTexture的实例崩溃了我的应用程序,但不知道如何调试这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆