我一般来说对libgdx还是陌生的。基本上,我有一个弹跳球的世界,我只是在尝试一下。在我将摄像机固定在这样的位置之前:
在将以下行放入render方法之后,相机将继续跟踪播放器(即圆圈):
camera.position.set(player.getPosition().x, player.getPosition().y, 0);
Run Code Online (Sandbox Code Playgroud)
玩家是身体类型。
因此,当我这样做时,它确实会跟随播放器,但是形状渲染器现在的行为很奇怪。看看会发生什么:
即使我将播放器的x和y位置指的是相机和形状渲染器,但它们的位置也不相同。
这是我的代码:
public class Game extends ApplicationAdapter {
World world = new World(new Vector2(0, -9.8f), true);
Box2DDebugRenderer debugRenderer;
OrthographicCamera camera;
static final int PPM = 100;
static float height,width;
Body player;
RayHandler handler;
PointLight l1;
ShapeRenderer shapeRenderer;
@Override
public void create() {
shapeRenderer = new ShapeRenderer();
height = Gdx.graphics.getHeight();
width = Gdx.graphics.getWidth();
//set camera
camera = new OrthographicCamera();
camera.setToOrtho(false, (width)/PPM/2, (height)/PPM/2);
camera.update();
//Ground body
BodyDef groundBodyDef =new BodyDef();
groundBodyDef.position.set(new Vector2(width/PPM/2/2, 0)); …Run Code Online (Sandbox Code Playgroud) 我使用以下代码实现了JDatePicker:
final UtilDateModel expiryDateModel = new UtilDateModel();
Properties prop = new Properties();
prop.put("text.today", "Today");
prop.put("text.month", "Month");
prop.put("text.year", "Year");
final JDatePanelImpl expiryDatePanel = new JDatePanelImpl(expiryDateModel, prop);
final JDatePickerImpl expiryDatePicker = new JDatePickerImpl(expiryDatePanel, new DateLabelFormatter());
Run Code Online (Sandbox Code Playgroud)
我已经尝试过expiryDatePicker.setEnabled(false)但它似乎没有禁用它,因为用户仍然可以选择日期.对此有何解决方案?
我有一个Triple类,它是一个可以包含3个整数(x,y,z)的类.我想覆盖equals/hashcode方法,以便它们可以在一个集合中使用.所以带(1,2,3)的obj应该等于(3,2,1)或(3,1,2),所以应该等于它的任何排列.我知道如何使用(x,y)对Pair类执行此操作 - 我对此的对类的代码是:
class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Pair) {
Pair p = (Pair) obj;
if (this.x == p.x && p.y == this.y || this.x == p.y && this.y == p.x) {
return true;
}
}
return false;
}
@Override
public int hashCode() {
return Integer.hashCode(x) * Integer.hashCode(y);
}
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但如果我想将它扩展为Triple类,我知道我可以编辑equals方法并添加更多条件来检查,但这似乎很长.如果不在Java中使用外部库,我有什么方法可以做到这一点?