嗨 Raj 感谢您的快速响应实际上我的问题是我必须将精灵移动到我触摸过的触摸点,而且我只想沿着 x 轴移动该精灵,为此我使用以下代码
- (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];
}}}}
使用此代码可以将我的精灵移动到我想要的任何位置,但它不限于 x 轴......所以你能帮我解决这个问题吗
提前致谢