![](/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.