无法获取精灵位置
我的代码中有一些我已经做过很多次的东西,但现在我不能!
for (b2Body* bo = world->GetBodyList(); bo; bo = bo->GetNext())
{
CCSprite *tempSprite = (CCSprite *) bo->GetUserData();
NSLog(@"%f",tempSprite.position.x); //crashes in this line.
我正在数我的世界上的尸体,我可以看到我有 22 个尸体,但每次我尝试使用 tempSprite.position.x
做某事时,它都会崩溃!
我还可以打印这个:
if(tempSprite != NULL)
NSLog(@"YES");
为什么我无法获得该职位? 我的世界运转良好;联系监听器做得很好;无法理解这一点。
有什么帮助吗?
I have somewhere in my code something that I have done so many times, but now I can't!
for (b2Body* bo = world->GetBodyList(); bo; bo = bo->GetNext())
{
CCSprite *tempSprite = (CCSprite *) bo->GetUserData();
NSLog(@"%f",tempSprite.position.x); //crashes in this line.
I am counting the bodies on my world and I can see i have 22 of them, but every time i try to do somthing with: tempSprite.position.x
it crashes!
I can also print this:
if(tempSprite != NULL)
NSLog(@"YES");
Why can't I get the position?
My world is working great; the contact listener is doing just fine; can't understand that.
any help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了,但不清楚为什么
我这样做
,因为shiftEnemies是我发布的函数,它在所有主体上运行。
我已更正为:
并且它有效。
那是因为我跑过我的身体,其中一些没有用户数据,因为我已经清理了精灵!
所以你必须摧毁身体并清理精灵,然后从你的身体上跑过去。
结论:不要清洁你的精灵,在摧毁你的身体之前做点别的事情!
听起来合理吗?
solved but not clearly why
i did
when shiftEnemies is the function that i have posted-that runs on all the bodies.
i have corrected to:
and it works.
that was because i was running over my bodies, which some of them didnt have a userData, because i already cleaned up the sprite !
so you have to destroy body and clean the sprite and then run over your bodies.
conclusion: DO NOT CLEAN YOUR SPRITE, AND DO SOMETHING ELSE BEFOR YOU DESTROY YOUR BODY !
sounds reasonable ?