碰撞为什么不同的表现在Android中比iOS的? [英] Why do collisions behave differently in Android than in iOS?

查看:262
本文介绍了碰撞为什么不同的表现在Android中比iOS的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Box2D的独立模拟精灵我的物理世界,更新我的精灵的基础上b2body的位置的位置。

I am using Box2D to simulate the physics world independently of my sprites, and I update the position of my sprites based on the position of b2body.

我有一个由两个固定装置的球员。一夹具是不是一个传感器,可以使与地面接触。另夹具是一个传感器,用于检查了这些东西,通电果蔬粥等联系方式。

I have a player that consists of two fixtures. One fixture is not a sensor and can make contact with the ground. The other fixture is a sensor and is used to check for contacts with things like powerups eatables etc.

。我有一些机构(果蔬粥,权力),其中固定装置由一个传感器,可以使与球员接触传感器的。

. I have some bodies (eatables, powers) in which the fixture consists of a single sensor that can make contact with the player sensor.

在iOS的一切工作正常 - 当玩家与开机/食用,他继续运行,如果没有什么是错的碰撞。但在Android的他反弹的通电。

In iOS everything works fine - when the player collides with the powerup / eatable, he continues running as if nothing is wrong. But in Android he bounces off the powerup.

这可能是什么问题呢?通过物理编辑器生成的plist文件是上是相同的。仿真为什么应该是不同的? Box2D的是cocos2d的的一部分,所以该库是相同的,并应是既相同。

What could be the problem ? The plist file generated by physics editor is the same for both. Why should the simulation be different ? Box2d is part of cocos2d, so the library is the same and should be the same for both.

我使用了cocos2d-X 3.7。

I am using cocos2d-x 3.7.

编辑:我用的是以下内容:

I use the following:

ContactListener.h类:

ContactListener.h class:

class ContactListener : public b2ContactListener {

public:


    void BeginContact(b2Contact* contact) {
        void* bodyUserDataA = contact->GetFixtureA()->GetBody()->GetUserData();
        if (bodyUserDataA) {

        }
    }

    void EndContact(b2Contact* contact) {

    }
};

我ContactListener.cpp是空的。

my ContactListener.cpp is empty.

X $ C $ç自动处理正确,事情的一切建设只是工作。在Android上,我曾在Application.mk指定我的cpp文件,所以我不知道这是否会导致一些不同的行为,因为我没有在任何地方指定.h文件。

Xcode automatically handles building everything properly and things "just work". On Android, I had to specify my cpp files in Application.mk, so I wonder whether this could cause some different behaviour, because I am not specifying the .h files anywhere.

推荐答案

这是由于该PhysicsEditor文件提供了GB2ShapeCache.cpp的错误。虽然isSensor布尔检查中的iOS / OS X的作品,在Android中并不按预期并将其设置为false,而不是真实的。

This is due to a bug in GB2ShapeCache.cpp provided by the PhysicsEditor file. While the boolean check for isSensor works in iOS / OS X , in Android it doesn't work as expected and sets it to false instead of true.

解决方法:

#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
            basicData.isSensor = (bool)static_cast<CCString *>(fixtureData->objectForKey("isSensor"))->intValue();
#else
            CCString *foo = static_cast<CCString *>(fixtureData->objectForKey("isSensor"));
            const char *s = foo->getCString();
            if (s==NULL) {
                basicData.isSensor = false;
            }else{
                std::string str(s);
                if (str=="true") {
                    basicData.isSensor = true;
                }else{
                    basicData.isSensor = false;
                }
            }
#endif

这篇关于碰撞为什么不同的表现在Android中比iOS的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆