无法获取精灵位置

发布于 2025-01-02 02:46:31 字数 523 浏览 0 评论 0原文

我的代码中有一些我已经做过很多次的东西,但现在我不能!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2025-01-09 02:46:31

解决了,但不清楚为什么

我这样做

        [badBondSheet1 removeChild:actora cleanup:YES];
        [self removeChild:actorb cleanup:YES];
        [self shiftEnemies:touchPointA]; // calls the code that i have posted 

,因为shiftEnemies是我发布的函数,它在所有主体上运行。

我已更正为:

       [self shiftEnemies:touchPointA];
    [badBondSheet1 removeChild:actora cleanup:YES];
    [self removeChild:actorb cleanup:YES];

并且它有效。

那是因为我跑过我的身体,其中一些没有用户数据,因为我已经清理了精灵!

所以你必须摧毁身体并清理精灵,然后从你的身体上跑过去。
结论:不要清洁你的精灵,在摧毁你的身体之前做点别的事情!

听起来合理吗?

solved but not clearly why

i did

        [badBondSheet1 removeChild:actora cleanup:YES];
        [self removeChild:actorb cleanup:YES];
        [self shiftEnemies:touchPointA]; // calls the code that i have posted 

when shiftEnemies is the function that i have posted-that runs on all the bodies.

i have corrected to:

       [self shiftEnemies:touchPointA];
    [badBondSheet1 removeChild:actora cleanup:YES];
    [self removeChild:actorb cleanup:YES];

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 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文