![](/img/trans.png)
[英]iPhone, Cocos2D - moving sprite left/right while touching screen
[英]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.