• 日志输出

    日志输出

    有时,在你的游戏正在运行的时候,为了了解程序的运行过程或是为了查找一个 BUG,你想看到一些运行时信息,可以! 这个需求引擎已经考虑到了,使用 log() 可以把信息输出到控制台,这样使用:

    1. // a simple string
    2. log("This would be outputted to the console");
    3. // a string and a variable
    4. string s = "My variable";
    5. log("string is %s", s);
    6. // a double and a variable
    7. double dd = 42;
    8. log("double is %f", dd);
    9. // an integer and a variable
    10. int i = 6;
    11. log("integer is %d", i);
    12. // a float and a variable
    13. float f = 2.0f;
    14. log("float is %f", f);
    15. // a bool and a variable
    16. bool b = true;
    17. if (b == true)
    18. log("bool is true");
    19. else
    20. log("bool is false");

    对于使用 C++ 进行游戏开发的用户来说,可能想使用 std::cout 而不用 log(),实际上 log() 更易于使用,它格式化复杂的输出信息更简单。