java - Libgdx 保持代码整洁

标签 java libgdx

我编写了以下代码。一切正常。但是,我被告知它的格式不正确。我不太确定正确的编码方式是什么。任何帮助或指导将不胜感激。

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/

相关文章:

java - CPLEX (12.5) Java API,将 LP 解析为 IP

opengl - libgdx如何在3D中使用着色器

java - Actor 在 screen2d 中不动

java - 如何使用Input/OutputStream读取/写入数据而不创建新对象LibGDX

java - Sprite 不在位置上

android - startActivity(Intent intent) 在我的 LibGDX 项目的 Android 版本中不起作用

java - 在 JPA 中使用 Eager Fetch 的场合是什么?

java - 如何在Katalon Studio中读取Excel表格中的数据

java - Spring Boot 测试 - 如何在 Spring Boot 之前启动嵌入式服务器?

Java 7 监视服务 : avoiding an infinite loop of events when changing the event source in handler