【发布时间】:2018-11-04 01:35:14
【问题描述】:
所以我试图用 2d 数组生成一个 5x5 网格,但是当我尝试调用负责大小的渲染方法时它不起作用。此外,我使用矩形框作为网格中的图像。它们渲染得非常小。
package ksmd.tiles.Screens;
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.Texture;
import ksmd.tiles.Tiles;
import ksmd.tiles.UI.Tile;
public class PlayScreen implements Screen {
private Tiles game;
//Texture texture;
private Tile[][] tile;
private float boardOffset;
private OrthographicCamera orthographicCamera;
public PlayScreen(Tiles game) {
this.game = game;
//texture = new Texture("badlogic.jpg");
tile = new Tile[5][5];
int tileSize = Tiles.WIDTH / tile[0].length;
boardOffset = (Tiles.HEIGHT - (tileSize * tile.length)) / 2;
for (int row = 0; row < tile.length; row++) {
for (int col = 0; col < tile[0].length; col++) {
tile[row][col] = new Tile(col * tileSize / 2, row * tileSize + boardOffset + tileSize / 2, tileSize, tileSize);
}
}
// orthographicCamera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
@Override
public void show() {
}
@Override
public void render(float delta) {
//game.batch.setProjectionMatrix(orthographicCamera.combined);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
game.batch.begin();
for (int row = 0; row < tile.length; row++) {
for (int col = 0; col < tile[0].length; col++) {
tile[row][col].render(delta);
}
}
game.batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
package ksmd.tiles.UI;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import ksmd.tiles.Tiles;
public class Tile extends Box implements Screen {
private Tiles game;
private TextureRegion lit;
private TextureRegion dark;
private Sprite sprite;
private boolean selected;
public Tile(float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.height = height -8;
this.width = width - 8;
lit = Tiles.res.getAtlas("pack").findRegion("lit");
dark = Tiles.res.getAtlas("pack").findRegion("dark");
}
@Override
public void show() {
}
@Override
public void render(float delta) {
game.batch.begin();
game.batch.draw(lit, x- width/ 2, y- height/ 2, width, height);
game.batch.end();
}
public TextureRegion getTextureRegion(){
return lit;
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
基本上我是新手,不知道如何使用渲染方法使地图集在网格中更大。抱歉英语不好。
【问题讨论】:
-
@Squiddie 即使摄像头无法正常工作,也与屏幕无关:(