【问题标题】:Moving a sprite by touching anywhere on the screen通过触摸屏幕上的任意位置来移动精灵
【发布时间】:2013-05-21 11:13:13
【问题描述】:

在我的游戏中,只有一个精灵响应触摸。无论我在屏幕上的哪个位置触摸,如何让鼠标关节移动这个精灵/身体?

【问题讨论】:

  • 在触摸处理程序中总是返回yes。通常在触摸处理程序中,您会在允许处理触摸之前检查触摸边界,但您可以始终返回 yes,并按原样处理触摸。

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


【解决方案1】:
- (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;

【讨论】:

    猜你喜欢
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多