我有一个 void 函数,如果检测到触摸,它会使 Sprite 移动:
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
car.position = ccp(0,10);
}
游戏 rune 很好,但是当我触摸屏幕时,它在移动汽车 Sprite 时卡住了,感谢您的帮助!!
最佳答案
第一种方法是
[car setposition:location];
它会直接将您的汽车放置在您的触摸处。 其他方式是
[car runAction:[CCMoveTo actionWithDuration:1 position:location]];
检查拼写。我没有 IDE 来检查每个拼写。 :) 希望这有帮助
关于objective-c - 如何使用 cocos2d 在触摸上移动 Sprite ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9561697/