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

有帮助吗?

解决方案

做得好:

-(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

}

其他提示

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

查看Apple Dev Sample:MoveMe 我认为这会有所帮助。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top