纹理不显示 - Cocos2D 2.0 Alpha

时间:2022-03-23 18:59:11

I know Cocos2d 2.0 is in alpha and will obviously have certain issues with it. I am trying to convert several projects to use OpenGL 2.0 for multiple reasons, but am having one very strange issue.

我知道Cocos2d 2.0处于alpha状态,显然会有一些问题。我试图将多个项目转换为使用OpenGL 2.0有多种原因,但我有一个非常奇怪的问题。

When I start up a scene, my textures load as desired and everything works great. I then display some Apple UI elements that allow me to quit the scene. The scene and its view controller are deallocated, the director is told to end, and I return to another view. Then I press a UIButton that launches the scene again. The scene begins again and runs, but no textures are visible. Fonts load and display, audio loads and plays, but no textures are visible. When dumping info from the CCTextureCache, I can see that the desired textures are available in the cache ( [[CCTextureCache sharedTextureCache] dumpCachedTextureInfo] ). I have also tried clearing the cache before the scene is relaunched. No matter what, I can not see any textures or add nodes to the scene.

当我启动一个场景时,我的纹理按照需要加载,一切都很好。然后我显示一些允许我退出场景的Apple UI元素。场景及其视图控制器被取消分配,导演被告知结束,我回到另一个视图。然后我按下再次启动场景的UIButton。场景再次开始并运行,但没有纹理可见。字体加载和显示,音频加载和播放,但没有纹理可见。从CCTextureCache转储信息时,我可以看到缓存中有所需的纹理([[CCTextureCache sharedTextureCache] dumpCachedTextureInfo])。我还尝试在重新启动场景之前清除缓存。无论如何,我都看不到任何纹理或向场景添加节点。

There could be something wrong with how I reset the scene, or how the EAGLView is setup. Here is the code for starting said scene from a View Controller:

我如何重置场景或者如何设置EAGLView可能有问题。以下是从View Controller启动所述场景的代码:

(void)startGame {

CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [EAGLView viewWithFrame:[self.view bounds]];

[director setOpenGLView:glView];

[self setView:glView];
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
//[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene:[Cocos2DChipmunkScene scene]];
}

Then, the scene is quit, and the following is called:

然后,场景退出,并调用以下内容:

CCDirector *director = [CCDirector sharedDirector];

CCDirector * director = [CCDirector sharedDirector];

[[director openGLView] removeFromSuperview];

[[director openGLView] removeFromSuperview];

[director end];

The above startGame method is called again when I try to start the game again. This is the point where no textures are displayed.

当我尝试再次启动游戏时,再次调用上面的startGame方法。这是没有纹理显示的点。

Let me know if I need to provide more details on this issue.

如果我需要提供有关此问题的更多详细信息,请与我们联系。

1 个解决方案

#1


1  

My recommendation is to not shut down the director and keep the openGLView in the hierarchy, just set it as hidden: openGLView.hidden = YES;

我的建议是不关闭导向器并将openGLView保持在层次结构中,只需将其设置为隐藏:openGLView.hidden = YES;

You can start and stop cocos2d via [[CCDirector sharedDirector] startAnimation] respectively stopAnimation.

您可以分别通过[[CCDirector sharedDirector] startAnimation] stopAnimation启动和停止cocos2d。

#1


1  

My recommendation is to not shut down the director and keep the openGLView in the hierarchy, just set it as hidden: openGLView.hidden = YES;

我的建议是不关闭导向器并将openGLView保持在层次结构中,只需将其设置为隐藏:openGLView.hidden = YES;

You can start and stop cocos2d via [[CCDirector sharedDirector] startAnimation] respectively stopAnimation.

您可以分别通过[[CCDirector sharedDirector] startAnimation] stopAnimation启动和停止cocos2d。