0

我有一艘宇宙飞船。我想让飞船移动到玩家接触过的区域。到目前为止,我有这个代码:

- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

  // initialize touch
  UITouch *touch = [touches anyObject];

  // point out location of touch
  CGPoint location = [touch locationInView:[touch view]];

  // move to location
  [player runAction:[CCMoveTo actionWithDuration:0.5 position:location]];

  // log action
  CCLOG(@"player moved");

}

但是,这有一个怪癖:当我触摸某些地方时,梭子会缓慢移动,向上而不是向下,以及其他奇怪的动作。有什么办法可以纠正这个代码吗?

4

1 回答 1

2

行后:

 CGPoint location = [touch locationInView:[touch view]];

添加这一行:

location = [[CCDirector sharedDirector] convertToGL: location]; 

然后尝试。:)

于 2012-07-04T18:38:51.443 回答