knagode
knagode

Reputation: 6125

Drawing lines/points in cocos2d for iPhone is very slow

I am trying to draw coloured landscape around my game which is dynamically changing its shape and color when player moves on.

Even simple drawing couses framerate to drop to around 10 FPS.

-(void) draw {    
    glPointSize(1);
    glColor4ub(100,100,100,255);
    for(int i=0; i<100; i+=1){
        for (int j=0; j<100; j++){
            ccDrawPoint(ccp(i, j));
        }
    }
}

What could I do to make these operations work faster?

Upvotes: 0

Views: 1154

Answers (2)

knagode
knagode

Reputation: 6125

Drawing custom shapes with ccDrawPoint or ccDrawLine is not very good solution.

The best way to draw custom shape is to draw multiple triangles or even better - multiple polygons.

Check this thread to see how to do it: http://www.cocos2d-iphone.org/forum/topic/848

Upvotes: 1

Danyal Aytekin
Danyal Aytekin

Reputation: 4215

You're calling ccDrawPoint, and making a new CGPoint, 10,000 times a frame, which might cause some slowdown. Have you seen ccDrawSquare?

Upvotes: 1

Related Questions