iphone - I want to move sprite body when touch point detect -
i want move sprite body when touch screen cant happen...
-(void)cctouchended:(uitouch *)touch withevent:(uievent *)event { for(b2body *b=world->getbodylist();b;b=b->getnext()) { cgpoint location=[touch locationinview:[touch view]]; location=[[ccdirector shareddirector]converttogl:location]; b2vec2 locationworld = b2vec2(location.x/ptm_ratio, location.y/ptm_ratio); if(b->getuserdata()!=null) { ccsprite *sprite =(ccsprite *)b->getuserdata(); b->settransform(b2vec2(location.x, location.y), 0); id action = [ccmoveto actionwithduration:0.4 position:cgpointmake( b->getposition().x * ptm_ratio, b->getposition().y * ptm_ratio)]; [sprite runaction:action]; } } } please me... thanks
please try below code work you.
- (void)cctouchesended:(nsset *)touches withevent:(uievent *)event { for( uitouch *touch in touches ) { cgpoint location = [touch locationinview: [touch view]]; location = [[ccdirector shareddirector] converttogl: location]; for(b2body *b=world->getbodylist();b;b=b->getnext()) { if(b->getuserdata()!=null) { ccsprite *sprite =(ccsprite *)b->getuserdata(); b2vec2 locationworld = b2vec2(location.x/ptm_ratio, location.y/ptm_ratio); b->settransform(b2vec2(locationworld.x, locationworld.y), 0); id action = [ccmoveto actionwithduration:0.4 position:cgpointmake( b->getposition().x * ptm_ratio, b->getposition().y * ptm_ratio)]; [sprite runaction:action]; } } } } the sprite body moves location touch ended.
Comments
Post a Comment