簡體   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