JavaDevMatt.pl – Mateusz Kupilas

Programista, przedsiębiorca, gamedev, bloger.

LibGDX – GameplayScreen i nasz gracz

Kod źródłowy: https://github.com/JavaDevMatt/tutorialclicker/tree/tut3

Pamiętajcie, że film ma na celu pokazanie całej otoczki – od planowania, przez commitowanie, naprawienie błędów etc. Nie przepisujcie kodu z filmiku. Macie stan kodu z tego filmiku dostępny na Githubie.

Klasa Player

package pl.javadevmatt.tutorialclicker.entities;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

public class Player extends Image{

	private final static int WIDHT = 77;
	private final static int HEIGHT = 152;
	
	private final static int STARTING_X = 200;
	private final static int STARTING_Y = 300;
	
	public Player(){
		super(new Texture("badlogic.jpg"));
		
		this.setOrigin(WIDHT / 2, HEIGHT / 2);
		this.setSize(WIDHT, HEIGHT);
		
		// starting position
		this.setPosition(STARTING_X, STARTING_Y);
	}
	
}

Klasa GameplayScreen

package pl.javadevmatt.tutorialclicker.screens;

import pl.javadevmatt.tutorialclicker.TutorialClickerGame;
import pl.javadevmatt.tutorialclicker.entities.Player;

public class GameplayScreen extends AbstractScreen{
	
	private Player player;

	public GameplayScreen(TutorialClickerGame game) {
		super(game);
		init();
	}

	private void init() {
		initPlayer();
	}

	private void initPlayer() {
		player = new Player();
		stage.addActor(player);
	}
	
	@Override
	public void render(float delta) {
		super.render(delta);
		update();
		
		spriteBatch.begin();
		stage.draw();
		spriteBatch.end();
	}

	private void update() {
		stage.act();
	}

}

banerjd