ios - Cocos2d-iphone. "touchBegan" method and returning a value -
i developing game using cocos2d-iphone 3.0. use bool make code inside (after user touches sprite) implemented once. when user touches sprite second time, code not implemented. problem is, xcode says touchbegan method should not return value ( return no ;). how can change method, there no mistake? should change else? way correct @ all?
bool firstclicked = false; -(void) touchbegan:(uitouch *)touch withevent:(uievent *)event { if(firstclicked==true) { return no ; } cgpoint location = [touch locationinview: [touch view]]; cgpoint convertedlocation = [[ccdirector shareddirector] converttogl: location]; cgpoint convertednodespacepoint = [self converttonodespace:convertedlocation]; if (cgrectcontainspoint([_sprite boundingbox],convertednodespacepoint)) { firstactfirsttimeclicked=true; .......// code. not important } }
if need once, want deactivate touch began on sprite. in custom overriden sprite :
-(void) touchbegan:(uitouch *)touch withevent:(uievent *)event { { // awesome game related code on here self.userinteractionenabled = no; } this should work on custom ccsrpite. way don't have handle silly position code in scene, , ready go 1 line of code.
obviously need enable user interaction when creating ccspritein order touchbegan called in first place.
Comments
Post a Comment