[英]how can i move a sprite on touch using cocos2d?
我有这个虚函数,如果检测到触摸,则使精灵移动:
-(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);
}
游戏运行正常,但是当我触摸屏幕时,它会移动汽车精灵而冻结,谢谢您的帮助!
1种方法是
[car setposition:location];
它会直接将您的汽车放在您的触摸处。 其他方式是
[car runAction:[CCMoveTo actionWithDuration:1 position:location]];
检查拼写。 我没有IDE检查每个拼写。 :) 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.