0
嗨拉吉感谢您的快速反应,实际上我的问题是我必须将精灵移动到触摸点,并且我只想沿着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轴......这样你们可以帮我对此
感谢提前
HMM的点的坐标,我不熟悉的Box2D – stenger96