Game Development Reference
In-Depth Information
@Override
public void dispose() {
modelBatch.dispose();
assets.dispose();
}
...
}
The difference from our previous MyModelTest.java file is that we added an array
of model instances instead of one. Note that there is only one model and 12 model
instances. The position of the camera is also changed to ( 5 , 20 , 20 ). The updated code is
highlighted. You can use the mouse or W , S , A , D keys to navigate. However, with the
current code, every model instance is drawn, whether they are in the scene or not.
In order to check this, let's update the code and add some strings to the scene
as follows:
...
public OrthographicCamera orthoCam;
public SpriteBatch spriteBatch;
public BitmapFont font;
public StringBuilder stringBuilder = new StringBuilder();
@Override
public void create() {
...
orthoCam = new OrthographicCamera(Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
orthoCam.position.set(Gdx.graphics.getWidth() / 2f,
Gdx.graphics.getHeight() / 2f, 0);
spriteBatch = new SpriteBatch();
font = new BitmapFont();
}
@Override
public void render() {
...
modelBatch.begin(cam);
int count = 0;
for (ModelInstance instance : instances) {
modelBatch.render(instance, environment);
count++;
}
modelBatch.end();
 
Search WWH ::




Custom Search