@abrajam wrote:
Hi, I putted a physics body to all my sprites that I want to check for collision, but I really not want to use the other physics features like gravity, friction, etc just need a more precise collision than just checking for intersection between bounding boxes.
The thing is that when I set
physicsworld
andphysicbodies
my characters get moving very fast compared to the movement made without setting a physics world. I move them on the game withsetPositionY(getPositionY + speed * dt)
I mean no physic forces, is there a way to prevent what is happening? Please give me some help because I think that they are kinematic bodies and shouldn’t be affected this way by the physics but somehow they do and I can’t find the setting to prevent it, also the documentation is out of my understanding and it differs between classical BOX2D and the implementation of cocos2d-x of this library.On my scene I set this:
#if _USE_PHYSICS == 1 if (!Scene::initWithPhysics()) return false; //getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL); getPhysicsWorld()->setGravity(Vec2(0.0f, 0.0f)); getPhysicsWorld()->setSpeed(0.0f); MyBodyParser::getInstance()->parseJsonFile("Physics"); #elif _USE_PHYSICS == 0 if (!Scene::init()) return false; #endif
and in my characters like this, I vary the 3 parameters for Physics Material but I see no difference:
if (!Sprite::initWithSpriteFrameName(_ENEMY_IDLE_PATH)) return false; #if _USE_PHYSICS == 1 auto phBody = MyBodyParser::getInstance()->bodyFormJson(this, "Enemy", PhysicsMaterial(1.0f, 0.0f, 10.0f)); phBody->setDynamic(false); phBody->setGravityEnable(false); this->setPhysicsBody(phBody); #endif
and like this:
if (!Sprite::initWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(filename))) return false; setVisible(false); #if _USE_PHYSICS == 1 auto phBody = MyBodyParser::getInstance()->bodyFormJson(this, (_type == UP_BULLET) ? "BulletPlayer" : "BulletEnemy", PhysicsMaterial(10.0f, 0.0f, 10.0f)); phBody->setDynamic(false); phBody->setGravityEnable(false); this->setPhysicsBody(phBody); #endif
Hope somebody could help, thanks.
Posts: 1
Participants: 1