通过触摸屏幕上的任何位置移动精灵

时间:2013-05-21 11:13:14

标签: ios cocos2d-iphone box2d box2d-iphone uitouch

在我的游戏中只有一个精灵响应触摸。无论我在屏幕上触摸什么位置,如何使鼠标连接移动此精灵/身体?

1 个答案:

答案 0 :(得分:0)

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];

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

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

mySprite.position = location;

}

确保init方法self.isTouchEnabled = YES;