繁体   English   中英

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

[英]Moving a sprite by touching anywhere on the screen

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM