gpt4 book ai didi

objective-c - 如何使用 cocos2d 在触摸上移动 Sprite ?

转载 作者:行者123 更新时间:2023-11-29 04:46:32 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com