如何在Cocos2d中实现“拖动”选项?

时间:2009-03-05 08:45:16

标签: iphone objective-c cocos2d-iphone

我尝试使用Cocos2d为iPhone开发游戏。我需要Cocos2d中的'DRAG'选项。是否可以在Cocos2d中实现拖动选项?

2 个答案:

答案 0 :(得分:1)

做得好:

-(BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    CGPoint location = [touch locationInView: [touch view]];
    CGPoint convertedLocation = [[Director sharedDirector] convertCoordinate:location];
        //start ur logical code

}

答案 1 :(得分:0)

要拖动,只需将精灵的中心设置为当前触摸坐标的位置即可。

See the Apple Dev Sample: MoveMe我认为这会有所帮助。

您是否正在尝试创建像Flight Control或Harbor Master这样的寻路游戏?请详细解释您想要实现的目标。