我编写了以下代码。一切正常。但是,我被告知它的格式不正确。我不太确定正确的编码方式是什么。任何帮助或指导将不胜感激。
package com.mygdx.gameworld;
import com.badlogic.gdx.Gdx;
import com.mygdx.gameobjects.Egg;
import com.mygdx.gameobjects.Ground;
import com.mygdx.gameobjects.Hero;
public class GameWorld {
Hero hero = new Hero(); //This seems to the bit that causes some amusement.
Egg egg = new Egg(); //This seems to the bit that causes some amusement.
Ground ground = new Ground(); //This seems to the bit that causes some amusement.
public void update(float delta) {
Gdx.app.log("GameWorld", "update");
egg.update(delta);
hero.update(delta);
ground.update(delta);
}
public Hero getHero() {
return hero;
}
public Egg getEgg() {
return egg;
}
public Ground getGround() {
return ground;
}
}
最佳答案
那些被注释的变量是你的类的成员。它们没有修饰符,这意味着它们仅在类内部或同一包中的类中可见。例如,如果您想在测试时模拟它们,这绝对是有道理的。在其他情况下,我不建议使用它们,而是将它们设置为私有(private)。
有关修饰符和类成员的更多信息:http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
关于java - Libgdx 保持代码整洁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29186118/