我在OS X上使用Cocos2D 2.0收到此警告:
- [CCRenderTexture initWithWidth:height:pixelFormat:depthStencilFormat:]:cocos2d:警告。 CCRenderTexture在自己的线程上运行。确保在此线程上使用OpenGL上下文!
以下是我认为导致警告的代码:
- (id) initWithObject: (CCNode *) object mask: (CCSprite *) mask {
NSAssert(object != nil, @"Invalid sprite for object");
NSAssert(mask != nil, @"Invalid sprite for mask");
if((self = [super init])) {
_objectSprite = object;
_maskSprite = mask;
// Set up the burn sprite that will "knock out" parts of the darkness layer depending on the alpha value of the pixels in the image.
[_maskSprite setBlendFunc: (ccBlendFunc) { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }];
// Get window size, we want masking over entire screen don't we?
CGSize size = [[CCDirector sharedDirector] winSize];
// Create point with middle of screen
CGPoint screenMid = ccp(size.width * 0.5f, size.height * 0.5f);
// Create the rendureTextures for the mask
_masked = [CCRenderTexture renderTextureWithWidth: size.width height: size.height];
[[_masked sprite] setBlendFunc: (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }];
// Set render textures at middle of screen
_masked.position = screenMid;
// Add the masked object to the screen
[self addChild: _masked];
[[CCDirector sharedDirector] setAlphaBlending:YES];
}
return self;
}
请帮助,我只是想不出来。
答案 0 :(得分:0)
在ccConfig.h
中,找到一行
#define CC_DIRECTOR_MAC_THREAD CC_MAC_USE_DISPLAY_LINK_THREAD
这是定义线程使用的地方。您可以尝试使用主线程选项(CC_MAC_USE_MAIN_THREAD
),或使用GCD确保所有代码都在-[CCDirector runningThread]
上实际执行。这几乎可以解决它。