Ejemplo n.º 1
0
cocos2d::Sprite& JsonLoader::createPhysicsSprites(b2dJsonImage& def)
{
    auto sprite = Sprite::create(box2dContainer, *def.body, def.file);
    if (!sprite) {
        throw new std::invalid_argument(std::string("Unable to load sprite: " + def.file));
    }

    sprite->setPositionOffset({def.center.x, def.center.y});
    sprite->setRotationOffset(CC_RADIANS_TO_DEGREES(-def.angle));

    bodySprites[def.body].push_back(sprite);
    return *sprite;
}
Ejemplo n.º 2
0
void PhysicsBody::onAdd()
{
    _owner->_physicsBody = this;
    auto contentSize = _owner->getContentSize();
    _ownerCenterOffset.x = 0.5f * contentSize.width;
    _ownerCenterOffset.y = 0.5f * contentSize.height;

    setRotationOffset(_owner->getRotation());

    // component may be added after onEnter() has been invoked, so we should add
    // this line to make sure physics body is added to physics world
    addToPhysicsWorld();
}