cocoa touch - Getting location of sprite within array cocos2d` -
i need able touch specific moving sprite in array , perform action on it. when perform moveto action, sprite location doesn't update. help!
array:
int numbreds = 7; redbirds = [[ccarray alloc] initwithcapacity: numbreds]; for( int = 1; i<=numbreds; i++){ int xvalue = ((-50*i) + 320); int yvalue= 160; if (i==4) { ccsprite *parrot = [ccsprite spritewithfile:@"taco.png"]; [birdlayer addchild:parrot]; [self movement]; //the action moves array horizontally parrot.position = ccp(xvalue,yvalue); parrot.tag=100; touch
-(void)cctouchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [touches anyobject]; cgpoint location = [touch locationinview:[touch view]]; location = [[ccdirector shareddirector] converttogl:location]; ccsprite *mark = (ccsprite *)[birdlayer getchildbytag:100]; if (cgrectcontainspoint([mark boundingbox], location)) { cclog(@"yay!"); } the problem location of ccsprite doesn't update or move. yay! generated @ origin location of sprite.
try this:
ccsprite *temp = [ccsprite spritewithfile:@"taco.png"]; temp = [birdlayer getchildbytag:100]; if (temp.position.x == location.x) { // stuff... }
Comments
Post a Comment