I have a render loop that I want to run in the background so that I can control the speed of the playback loop making it animate either slow or fast. Right now I’m using sleep and calling begin and end on the CCRenderTexture in the main thread each time I want to use the sprite:
[self performSelectorOnMainThread:@selector(visit) withObject:nil waitUntilDone:YES];
- (void)visit {
[target begin];
[[self.currentLine.brush sprite] visit];
[target end];
}
This was a hack that got it working but of course makes it run very slow. calling begin and end in the background thread just causes nothing to render at all
I want to be able to call begin, do all my drawing in the background thread and then call end but everything I’ve tried has either done nothing or made my EAGLView flip out.
The
CCRenderTexureworks by redirecting the opengl output onto itself so that the drawing that gets done is saved on your sprite. This means that in a single operation you need to callbegindo all your drawing and then callend.When running on a background thread the
CCDirectoris making it’s own draw calls in the main thread so that when you call begin and try to do multiple functions in that state the director is drawing too causing all sorts of strange errors.endneeds to be called before normal rendering operations resume.