opengl es - Cocos2d - only one scheduler called -
i'm trying trace 2 paths on screen through series of vertices (connect dots style). each should different color, , each has own list of vertices.
i started out creating class can trace path, creating 2 instances of class, 1 each path. overrode draw method. worked fine except reason first instance of class called draw method. figured problem opengl did 1 time again using ccdrawnode , still had same bug.
only 1 instance (blackpath) draws objects on screen. in fact scheduled updateendpoint: method not called whitepath object, although created.
my drawer.m class:
const float size = 10; const float speed = 5; cccolor4f pathcolor; int numpoints; nsarray * path; cgpoint endpoint; @implementation drawer -(id)initwithpath:(nsarray*)p andcolorisblack:(bool)isblack{ self = [super init]; // record input path = p.copy; pathcolor = ccc4f(1.0f, 1.0f, 1.0f, 1.0f); if(isblack){ pathcolor = ccc4f(0.0f, 0.0f, 0.0f, 1.0f); } // set variables numpoints = 1; endpoint = [[path firstobject] position]; nslog(@"drawer initialized path of length %u , color %hhd (isblack)", p.count, isblack); [self schedule:@selector(updateendpoint:)]; homecoming self; } -(void)updateendpoint:(cctime)dt{ nslog(@"(%f, %f, %f, %f) path", pathcolor.r, pathcolor.g, pathcolor.b, pathcolor.a); [self drawdot:endpoint radius:size color:pathcolor]; cgpoint dest = [[path objectatindex:numpoints] position]; float dx = dest.x - endpoint.x; float dy = dest.y - endpoint.y; // new coords current + distance * sign of distance float newx = endpoint.x + min(speed, fabsf(dx)) * ((dx>0) - (dx<0)); float newy = endpoint.y + min(speed, fabsf(dy)) * ((dy>0) - (dy<0)); endpoint = ccp(newx, newy); if(endpoint.x == dest.x && endpoint.y == dest.y){ if(numpoints < path.count-1){ numpoints+=1; } else{ [self unschedule:@selector(updateendpoint:)]; } } }
and here instantiate objects:
-(id) init{ self = [super init]; [self addallcards]; [self addscore]; xshrinkrate = [[grid getinstance] sqwidth] / shrinktime; yshrinkrate = [[grid getinstance] sqheight] / shrinktime; droplist = [nsmutablearray new]; notdroplist = [nsmutablearray new]; [self schedule:@selector(dropcard:) interval:0.075]; [self schedule:@selector(shrinkcards:)]; drawer * whitepath = [[drawer alloc] initwithpath:[[score getinstance] whitepath] andcolorisblack:false]; [self addchild:whitepath]; drawer * blackpath = [[drawer alloc] initwithpath:[[score getinstance] blackpath] andcolorisblack:true]; [self addchild:blackpath]; homecoming self; }
change (non-const) global variables instance variables of class so:
@implementation drawer { cccolor4f pathcolor; int numpoints; nsarray * path; cgpoint endpoint; }
opengl-es cocos2d-iphone
No comments:
Post a Comment