Hi Raj Thanks for quick response actually what my problem was i have to move a sprite to touch point where ever i touched and also i want to move that sprite along x axis only, for that i use the following code
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches ) {
location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
for(b2Body *b=world->GetBodyList();b;b=b->GetNext()){
if(b->GetUserData()!=NULL) {`
CCSprite *myActor =(CCSprite *)b->GetUserData();
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
b->SetTransform(b2Vec2(locationWorld.x, locationWorld.y),0);
NSLog(@"x position of baby sprite is %@", b->GetPosition().x);
id action = [CCMoveTo actionWithDuration:0.4 position:CGPointMake( b->GetPosition().x, b->GetPosition().y)];
[myActor runAction:action];
}}}}
with this code am moving my sprite where ever i want but its not restricted to x axis…… So can u please help me regarding this
thanks in advance
try to use this code:
//coordinates of the point where we are touching
//action to move the sprite
}