使用相机LibGDX移动BitmapFont

时间:2016-10-27 14:35:28

标签: javascript java android camera libgdx

您好我是LibGDX的初学者。 我有一个移动的相机,我想在相机移动时显示得分。 我已经完成了这个,但是当相机移动时,文字(分数)会震动。 我不知道如何解决这个问题。 这是我的代码。

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/techdevabhi/hadoop-2.7.2/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

Logging initialized using configuration in jar:file:/usr/local/hive/lib/hive-common-2.1.0.jar!/hive-log4j2.properties Async: true
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
    at org.apache.hadoop.fs.Path.initialize(Path.java:205)
    at org.apache.hadoop.fs.Path.<init>(Path.java:171)
    at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:631)
    at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:550)
    at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:518)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:705)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:641)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
    at java.net.URI.checkPath(URI.java:1823)
    at java.net.URI.<init>(URI.java:745)
    at org.apache.hadoop.fs.Path.initialize(Path.java:202)
    ... 12 more

1 个答案:

答案 0 :(得分:0)

它震动的原因是默认情况下文本位置四舍五入为整数位置。您可以在每个文本对象上设置font.setUseIntegerPositions(false)以避免这种情况。

但是,尝试使用游戏世界的相机移动GUI是不切实际的。为您的GUI创建一个单独的相机。

public void render(SpriteBatch sb) {
    sb.setProjectionMatrix(gameCam.combined);
    sb.begin();

    sb.draw(bg,gameCam.position.x - (gameCam.viewportWidth /2),0);

    sb.draw(groud,groundpos1.x,groundpos1.y);
    sb.draw(groud,groundpos2.x,groundpos2.y);


    sb.setProjectionMatrix(guiCam.combined);
    String s = Integer.toString(SCORE);
    String h = Integer.toString(highscore);
    font.draw(sb, s, font.getSpaceWidth(), guiCam.viewportHeight / 2 - 39);
    high.draw(sb, h, guiCam.viewportWidth /2, guiCam.viewportHeight / 2 - 39);
    sb.end();
}