我有一艘宇宙飞船。我希望宇宙飞船能够移动到玩家触摸过的区域。到目前为止,我有这段代码:
- (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");
}
然而,这有一个怪癖:当我在某些地方触摸时,航天飞机将移动缓慢,向上而不是向下移动,以及其他奇怪的动作。有没有办法纠正这个代码?
答案 0 :(得分:2)
行后:
CGPoint location = [touch locationInView:[touch view]];
添加以下行:
location = [[CCDirector sharedDirector] convertToGL: location];
然后试试。 :)