EveSunMaple / InfinitySky

一个ExtraEasy2D的示例项目
https://www.saroprock.com/projects
3 stars 0 forks source link

问题:有关于多个相同的Object #7

Open EveSunMaple opened 7 months ago

EveSunMaple commented 7 months ago

现在每次调用新建都不得不重读文件,太慢了,需要预加载! 如:


// 发射子弹,father 中有需要的内容
BaseObject* NewBullet(BaseObject* father, const std::string& name)
{
    // 问题->
    Json::Value objectData = readJsonFromFile(BULLETS);
    const Json::Value object = objectData["bullets"][name];
    if (object == NULL) return nullptr;
    BaseObject* newObject = new BaseObject(5, false, nullptr, spriteMap[name], nullptr, nullptr, false);
    // sprite
    float fireSpeed = father->variable["fireSpeed"];
    float fireAngle = father->variable["fireAngle"];
    newObject->mass = object["sprite"]["mass"].asFloat();
    newObject->health = object["sprite"]["health"].asFloat();
    newObject->maxSpeed = object["sprite"]["maxSpeed"].asFloat();
    newObject->maxSpeedAngle = object["sprite"]["maxSpeedAngle"].asFloat();
    newObject->friction = object["sprite"]["friction"].asFloat();
    newObject->frictionAngle = object["sprite"]["frictionAngle"].asFloat();
    newObject->angle = father->angle + RandomNumber(-fireAngle, fireAngle);
    float Angle = Remainder(newObject->angle, 360) * (float)acos(-1) / 180;
    newObject->speedX = father->speedX + fireSpeed * sin(Angle);
    newObject->speedY = father->speedX + fireSpeed * cos(Angle);
    newObject->x = father->x;
    newObject->y = father->y;
    // variable
    newObject->variable["rotateAcceleration"] = object["sprite"]["rotateAcceleration"].asFloat();
    newObject->variable["forceAcceleration"] = object["sprite"]["forceAcceleration"].asFloat();
    newObject->variable["maxForce"] = object["sprite"]["maxForce"].asFloat();
    newObject->variable["liftTime"] = object["sprite"]["maxForce"].asFloat();
    // collisionBox
    for (const Json::Value point : object["collisionBox"])
        easy2d::Point(point[0].asFloat(), point[1].asFloat());
    newObject->Init(); // 初始化

    return newObject;
}

在下个dev提交修改

EveSunMaple commented 7 months ago

已在6ed3d6c提交中解决此问题

EveSunMaple commented 7 months ago

重新启用BaseObject复制函数,所有文件应该在启动前读完,Json::Value也必须在加载之后销毁

EveSunMaple commented 7 months ago

已在6ed3d6c提交中解决此问题

此条作废