开发者

Rendering painted lines as nodes in Cocos

I'm working on a drawing app for iPad using Cocos-iOS and I'm having performance issues with drawing lines as a type of CCNode. I understand that using draw in a node causes it to be called every time the canvas is repainted and the current code is very开发者_如何学C heavy if used every time:

for (LineNodePoint *point in self.points) {
    start = end;
    end = point;
    if (start && end) {
        float distance = ccpDistance(start.point, end.point);
        if (distance > 1) {
            int d = (int)distance;
            float difx = end.point.x - start.point.x;
            float dify = end.point.y - start.point.y;
            for (int i = 0; i < d; i++) {
                float delta = i / distance;

                [[self.brush sprite] setPosition:ccp(start.point.x + (difx * delta), start.point.y + (dify * delta))];
                [[self.brush sprite] visit];
            }
        }
    }
}

Very heavy...

I either need a better way to draw the lines or to be able to cache the drawing as a raster.

Thanks in advance for any help.


How about ccDrawLine or CCMutableTexture? CCMutableTexture is for manipulating pixels using CCRenderTexture internally as you said.

  • ccDrawLine

    • cocos2d for iPhone 1.0.0 API reference
  • CCMutableTexture

    • Fast set/getPixel for an opengl texture?
    • [render texture] pixel manipulation (integrated CCMutableTexture functionality)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜