Skip to main content
Commonmark migration
Source Link

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need).

In the render() method of your main game class call renderManager.render(). Now any code that would normally go in the main render method can be placed in the render method of your Renderer. It will be executed as it would if it were in your main class.

As for HUDS, well, I have never had need to use them, so I have no clue. This might be of use to you. You can probably find a few tutorials online with a simple Google search and I know there are multiple StackOverflow pages on it. Check out the api docs also.

This tutorial on the libGdx wiki teaches you how to use the Orthographic camera to use world coordinates instead of pixels and to avoid the headache that comes with using pixels. Since it is described so well on the linked page I will not even attempt to explain it better.

#EDIT:#

EDIT:

To create a HUD, you can use a seperate camera and overlay it. Do your game drawing first, then your HUD drawing. You could alternatively create a second SpriteBatch and not set the projection matrix to that of the camera. See below:

public void create()
{
    OrthographicCamera cam = new OrthographicCamera();
    

    SpriteBatch gameBatch = new SpriteBatch();
    SpriteBatch hudBatch = new SpriteBatch();
     
}

public void render()
{
    gameBatch.setProjectionMatrix(cam.combined);
    
    gameBatch.begin();
    //Draw using camera matrix
    gameBatch.end();

    hudBatch.begin();
    //Draw using the hud
    hudBatch.end();
}

You could alternatively use the camera.project(Vector3 coords) to draw to screen coordinates what you want. This will achieve the same results.

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need).

In the render() method of your main game class call renderManager.render(). Now any code that would normally go in the main render method can be placed in the render method of your Renderer. It will be executed as it would if it were in your main class.

As for HUDS, well, I have never had need to use them, so I have no clue. This might be of use to you. You can probably find a few tutorials online with a simple Google search and I know there are multiple StackOverflow pages on it. Check out the api docs also.

This tutorial on the libGdx wiki teaches you how to use the Orthographic camera to use world coordinates instead of pixels and to avoid the headache that comes with using pixels. Since it is described so well on the linked page I will not even attempt to explain it better.

#EDIT:#

To create a HUD, you can use a seperate camera and overlay it. Do your game drawing first, then your HUD drawing. You could alternatively create a second SpriteBatch and not set the projection matrix to that of the camera. See below:

public void create()
{
    OrthographicCamera cam = new OrthographicCamera();
    

    SpriteBatch gameBatch = new SpriteBatch();
    SpriteBatch hudBatch = new SpriteBatch();
     
}

public void render()
{
    gameBatch.setProjectionMatrix(cam.combined);
    
    gameBatch.begin();
    //Draw using camera matrix
    gameBatch.end();

    hudBatch.begin();
    //Draw using the hud
    hudBatch.end();
}

You could alternatively use the camera.project(Vector3 coords) to draw to screen coordinates what you want. This will achieve the same results.

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need).

In the render() method of your main game class call renderManager.render(). Now any code that would normally go in the main render method can be placed in the render method of your Renderer. It will be executed as it would if it were in your main class.

As for HUDS, well, I have never had need to use them, so I have no clue. This might be of use to you. You can probably find a few tutorials online with a simple Google search and I know there are multiple StackOverflow pages on it. Check out the api docs also.

This tutorial on the libGdx wiki teaches you how to use the Orthographic camera to use world coordinates instead of pixels and to avoid the headache that comes with using pixels. Since it is described so well on the linked page I will not even attempt to explain it better.

EDIT:

To create a HUD, you can use a seperate camera and overlay it. Do your game drawing first, then your HUD drawing. You could alternatively create a second SpriteBatch and not set the projection matrix to that of the camera. See below:

public void create()
{
    OrthographicCamera cam = new OrthographicCamera();
    

    SpriteBatch gameBatch = new SpriteBatch();
    SpriteBatch hudBatch = new SpriteBatch();
     
}

public void render()
{
    gameBatch.setProjectionMatrix(cam.combined);
    
    gameBatch.begin();
    //Draw using camera matrix
    gameBatch.end();

    hudBatch.begin();
    //Draw using the hud
    hudBatch.end();
}

You could alternatively use the camera.project(Vector3 coords) to draw to screen coordinates what you want. This will achieve the same results.

added content
Source Link
Jax
  • 474
  • 7
  • 22

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need).

In the render() method of your main game class call renderManager.render(). Now any code that would normally go in the main render method can be placed in the render method of your Renderer. It will be executed as it would if it were in your main class.

As for HUDS, well, I have never had need to use them, so I have no clue. This might be of use to you. You can probably find a few tutorials online with a simple Google search and I know there are multiple StackOverflow pages on it. Check out the api docs also.

This tutorial on the libGdx wiki teaches you how to use the Orthographic camera to use world coordinates instead of pixels and to avoid the headache that comes with using pixels. Since it is described so well on the linked page I will not even attempt to explain it better.

#EDIT:#

To create a HUD, you can use a seperate camera and overlay it. Do your game drawing first, then your HUD drawing. You could alternatively create a second SpriteBatch and not set the projection matrix to that of the camera. See below:

public void create()
{
    OrthographicCamera cam = new OrthographicCamera();
    

    SpriteBatch gameBatch = new SpriteBatch();
    SpriteBatch hudBatch = new SpriteBatch();
     
}

public void render()
{
    gameBatch.setProjectionMatrix(cam.combined);
    
    gameBatch.begin();
    //Draw using camera matrix
    gameBatch.end();

    hudBatch.begin();
    //Draw using the hud
    hudBatch.end();
}

You could alternatively use the camera.project(Vector3 coords) to draw to screen coordinates what you want. This will achieve the same results.

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need).

In the render() method of your main game class call renderManager.render(). Now any code that would normally go in the main render method can be placed in the render method of your Renderer. It will be executed as it would if it were in your main class.

As for HUDS, well, I have never had need to use them, so I have no clue. This might be of use to you. You can probably find a few tutorials online with a simple Google search and I know there are multiple StackOverflow pages on it. Check out the api docs also.

This tutorial on the libGdx wiki teaches you how to use the Orthographic camera to use world coordinates instead of pixels and to avoid the headache that comes with using pixels. Since it is described so well on the linked page I will not even attempt to explain it better.

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need).

In the render() method of your main game class call renderManager.render(). Now any code that would normally go in the main render method can be placed in the render method of your Renderer. It will be executed as it would if it were in your main class.

As for HUDS, well, I have never had need to use them, so I have no clue. This might be of use to you. You can probably find a few tutorials online with a simple Google search and I know there are multiple StackOverflow pages on it. Check out the api docs also.

This tutorial on the libGdx wiki teaches you how to use the Orthographic camera to use world coordinates instead of pixels and to avoid the headache that comes with using pixels. Since it is described so well on the linked page I will not even attempt to explain it better.

#EDIT:#

To create a HUD, you can use a seperate camera and overlay it. Do your game drawing first, then your HUD drawing. You could alternatively create a second SpriteBatch and not set the projection matrix to that of the camera. See below:

public void create()
{
    OrthographicCamera cam = new OrthographicCamera();
    

    SpriteBatch gameBatch = new SpriteBatch();
    SpriteBatch hudBatch = new SpriteBatch();
     
}

public void render()
{
    gameBatch.setProjectionMatrix(cam.combined);
    
    gameBatch.begin();
    //Draw using camera matrix
    gameBatch.end();

    hudBatch.begin();
    //Draw using the hud
    hudBatch.end();
}

You could alternatively use the camera.project(Vector3 coords) to draw to screen coordinates what you want. This will achieve the same results.

Source Link
Jax
  • 474
  • 7
  • 22

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need).

In the render() method of your main game class call renderManager.render(). Now any code that would normally go in the main render method can be placed in the render method of your Renderer. It will be executed as it would if it were in your main class.

As for HUDS, well, I have never had need to use them, so I have no clue. This might be of use to you. You can probably find a few tutorials online with a simple Google search and I know there are multiple StackOverflow pages on it. Check out the api docs also.

This tutorial on the libGdx wiki teaches you how to use the Orthographic camera to use world coordinates instead of pixels and to avoid the headache that comes with using pixels. Since it is described so well on the linked page I will not even attempt to explain it better.