objective c - Erasing Cocoa Drawing done by NSRectFill? -


i have nsbox, inside of drawing small rectangles, nsrectfill(). code looks this:

for (int = 0; <= 100; i++){       int x = (rand() % 640) + 20;     int y = (rand() % 315) + 196;      array[i] = nsmakerect(x, y, 4, 4);     nsrectfill(array[i]); } 

this loop creates 100 randomly placed rectangles within grid. have been trying create sort of animation, created code running on , over, creating animation of randomly appearing rectangles, code:

for (int = 0; <= 10; i++) {           [self performselector:@selector(executeframe) withobject:nil afterdelay:(.05*i)];         } 

the first loop thing inside executeframe function, way. so, need erase rectangles between frames, number of them stays same , moving. tried doing drawing background again, calling [mynsbox display]; before calling executeframe, made seem though no rectangles being drawn. calling after did same thing, did switching in setneedsdisplay instead of display. cannot figure 1 out, appreciated.

by way, additional thing when try run code executing frames, without trying erase rectangles in between, happens 100 more rectangles drawn. if have requested 1000 drawn, or 10,000. though, if leave window , come (immediately, time not factor here), page updates , rectangles there. attempted overcome [box setneedsdisplayinrect:array[i]]; worked in strange way, causing update every frame, erasing portions of rectangles. in appreciated.

it sounds you're drawing outside drawrect: . if that's case, move drawing code view's (the box's or subview's) drawrect: method. otherwise drawing stomped on cocoa drawing system you're seeing. you'll want use timers or animations rather loops repeated drawing.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -