Hi, I’m trying to make a Brick Bricker game,
need to know how to get camera width and height in world units to send the ball always to accurate edges in all screen sizes dynamically, i tried and also read docs didn’t get any clue, i used some values by my self to just go on but now need to make it accurate,
also i need another help at first i used to make singleton and use it in other class for sending rootNode and … . but i found out about it is very wrong soon, and used app-states i used a class name BallState and extended with BaseAppState Class as below, so is it good design paradigm with engine or am i completely wrong, i got it about states from documentations and a maze-game in github.
everything is so much primitive at a moment, but i want to go a lot further with game so any idea may help will appreciate it so much. view is locked at defaults and no fly cam,
/**
* The type BallState which will define Ball mesh,geo,update logic,and attach it to node.
*/
public class BallState extends BaseAppState {
private float xSpeed = 0.1f;
private float ySpeed = 0.1f;
private SimpleApplication app;
private Sphere ballMesh;
private Material ballMat;
private Geometry ballGeo;
@Override
protected void initialize(Application application) {
app = (SimpleApplication) application;
ballMesh = new Sphere(32,32, 0.1f);
ballGeo = new Geometry("ball", ballMesh);
ballMesh.setTextureMode(Sphere.TextureMode.Projected);
//TangentBinormalGenerator.generate(ballMesh);
ballMat = new Material(app.getAssetManager(),
"Common/MatDefs/Misc/Unshaded.j3md");
ballMat.setColor("Color", ColorRGBA.randomColor());
ballGeo.setMaterial(ballMat);
ballGeo.setLocalTranslation(0,-3,0);
ballGeo.rotate(1.6f, 0, 0);
app.getRootNode().attachChild(ballGeo);
}
@Override
public void update(float tpf) {
float x = ballGeo.getLocalTranslation().getX();
float y = ballGeo.getLocalTranslation().getY();
//System.out.println(x);
//System.out.println(y);
x += xSpeed;
y += ySpeed;
float wt = 5.3333335f;
if (x < -wt || x > wt) {
xSpeed = -xSpeed;
}
if (y < -4 || y > 4) {
ySpeed = -ySpeed;
}
ballGeo.setLocalTranslation(x,y,0);
}
@Override
protected void cleanup(Application application) {
}
@Override
protected void onEnable() {
}
@Override
protected void onDisable() {
}
}