HI,
i’m developing freehand drawing game, and in order to increase performance, i would use multithreading , i used this code:
void Canvas::onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *event) {
auto t = std::thread(&Canvas::drawEvenlySpacedSprites, this,touch->getLocation(),touch->getPreviousLocation());
t.detach();
}
void Canvas::drawEvenlySpacedSprites(Vec2 start, Vec2 end) {
// begin drawing to the render texture
_target->begin();
float distance = start.getDistance(end);
if (distance > 1) {
int d = (int)distance;
for (int i = 0; i < d; i++)
{
float difx = end.x - start.x;
float dify = end.y - start.y;
float delta = (float)i / distance;
Sprite * sprite = Sprite::create("brush3.png");
sprite->setColor(Color3B::BLUE);
sprite->setPosition(Vec2(start.x + (difx * delta), start.y + (dify * delta)));
sprite->visit();
}
}
// finish drawing and return context back to the screen
_target->end();
*/
}
But I have this error :
libpng warning: iCCP: known incorrect sRGB profile
cocos2d: Assert failed: Cannot add command while rendering
Assertion failed: (!_isRendering), function addCommand, file /Users/XXXXX/FreeDrawing/cocos2d/cocos/renderer/CCRenderer.cpp, line 268.
if i use t.join();
instead of t.detach();
, it work! , but it change the brush scale and the draw isn’t smooth
Help me please .
Thanks