I am trying to put Assets into my game but when i put in the line of code “batch.setProjectionMatrix(camera.combined);”, which from my knowledge scales the Asset to the size of the window it appears massive.
Here is my code:
MyGame.java:
package com.mygdx.mygame;
import com.badlogic.gdx.Game;
public class MyGame extends Game
{
public GameScreen game_screen;
@Override
public void create()
{
game_screen = new GameScreen(this);
setScreen(game_screen);
Assets.load();
}
}
GameScreen.java:
package com.mygdx.mygame;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class GameScreen implements Screen
{
MyGame mygame;
OrthographicCamera camera;
SpriteBatch batch;
public GameScreen(MyGame myGame)
{
camera = new OrthographicCamera();
camera.setToOrtho(true,1920,1080);
batch = new SpriteBatch();
}
@Override
public void show() {
}
@Override
public void render(float delta)
{
Gdx.gl30.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl30.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
batch.begin();
batch.draw(Assets.sprite_back, 0, 0);
batch.end();
batch.setProjectionMatrix(camera.combined);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
@Override
public void resize(int width, int height) {
}
}
Assets.java:
package com.mygdx.mygame;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
public class Assets
{
public static Texture texture_back;
public static Sprite sprite_back;
public static void load()
{
texture_back = new Texture(Gdx.files.internal("Play.jpg"));
texture_back.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sprite_back = new Sprite(texture_back);
sprite_back.flip(false, true);
}
}
DesktopLauncher.java:
package com.mygdx.mygame;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
public class Assets
{
public static Texture texture_back;
public static Sprite sprite_back;
public static void load()
{
texture_back = new Texture(Gdx.files.internal("Play.jpg"));
texture_back.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sprite_back = new Sprite(texture_back);
sprite_back.flip(false, true);
}
}
Please Help!