ОБНОВЛЕНИЕ Похоже, что это проблема из-за статической панели уведомлений на планшете из-за отсутствия аппаратных кнопок. Я просто об этом не думал. Во всяком случае, в случае TF101 он возвращает разрешение 1280x752, примерно, 1.702 (80: 47). Если я использую подходящий размер блока, например, 33,5 или 11,75 по вертикали, я получаю правильное масштабирование, и это, похоже, устраняет проблему перекошенных пикселей. END UPDATEПроблемы с пикселями libgdx между настольными и андроидными проектами
Я установил игру с использованием 16x16 единиц для мозаичных карт. Я использую разрешение 1280x800 как на моем рабочем столе, так и на проектах Android, я тестирую это, чтобы понять, как он будет выглядеть на моем планшете TF101 asus. В настоящее время я использую камеру с блоками 20x12.5 (wxh) и не вижу масштабирования пикселей на моем рабочем столе, но когда я запускаю игру на своем андроиде, я получаю странное масштабирование и зеленую горизонтальную линию. Я также могу перемещаться вокруг четвертной ячейки вдоль оси х на планшете, показанной на снимках экрана. Пиксели проекта андроида не кажутся однородными.
Я установил количество verticalTiles в 12.5f, а затем рассчитать количество horizontalTiles в
verticalTiles = 12.5f;
...
horizontalTiles = (float) width/(float) height * verticalTiles;
camera = new OrthographicCamera(horizontalTiles, verticalTiles);
Я прицеливания для устройств с различными пропорциями, чтобы просто увидеть более или менее карты, но не может похоже, работают правильно. Любая помощь будет оценена по достоинству.
Android Capture - http://imageshack.us/f/7/dsvg.png/ - обратите внимание на блики на краях крыши, они не являются равномерными.
Desktop Capture - http://imageshack.us/f/853/5itv.png/
Текущий MainGame класс
package com.bitknight.bqex;
/* Bunch of imports */
public class MainGame implements ApplicationListener {
private OrthographicCamera camera;
private SpriteBatch spriteBatch;
private TiledMap map;
private OrthogonalTiledMapRenderer mapRenderer;
private Texture texture;
private Texture clothArmor;
private Sprite sprite;
private BitmapFont font;
private float horizontalTiles = 0;
private float verticalTiles = 12.5f;
private int hoverTileX = 0;
private int hoverTileY = 0;
private TiledMapTileLayer layer;
private Cell cell;
private TiledMapTile canMoveToTile;
private TiledMapTile cannotMoveToTile;
private AnimatedTiledMapTile animatedStopTile;
private AnimatedTiledMapTile animatedGoTile;
private Texture spriteSheet;
private TextureRegion region;
private Player player;
float h, w;
float ppuX, ppuY;
@Override
public void create() {
// Setup the animated tiles
Array<StaticTiledMapTile> tileArray;
// Start position on the sheet
int startX = 192;
int startY = 1568;
spriteSheet = new Texture(Gdx.files.internal("data/maps/tilesheet.png"));
spriteSheet.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
// We are trying to load two strips of 4 frames, 8 total
for(int i = 0; i < 2; ++i) {
tileArray = new Array<StaticTiledMapTile>(4);
for(int j = 0; j < 4; ++j) {
region = new TextureRegion(spriteSheet, startX, startY, 16, 16);
tileArray.add(new StaticTiledMapTile(region));
startX += 16;
}
if(i == 0) {
animatedStopTile = new AnimatedTiledMapTile(1/10f, tileArray);
} else {
animatedGoTile = new AnimatedTiledMapTile(1/10f, tileArray);
}
}
// Load the map
map = new TmxMapLoader().load("data/maps/base.tmx");
// Setup the two tiles that show movable and not movable sprites
canMoveToTile = map.getTileSets().getTileSet(0).getTile(1959);
canMoveToTile.setBlendMode(BlendMode.ALPHA);
cannotMoveToTile = map.getTileSets().getTileSet(0).getTile(1958);
cannotMoveToTile.setBlendMode(BlendMode.ALPHA);
// Manually create the layer used to show the cursor sprites
layer = new TiledMapTileLayer(100, 100, 16, 16);
layer.setName("display");
cell = new Cell();
cell.setTile(canMoveToTile);
layer.setOpacity(1f);
mapRenderer = new OrthogonalTiledMapRenderer(map, 1/16f);
spriteBatch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("data/consolas.fnt"), false);
font.setScale(0.6f);
texture = new Texture(Gdx.files.internal("data/maps/tilesheet.png"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
clothArmor = new Texture(Gdx.files.internal("data/img/native/clotharmor.png"));
region = new TextureRegion(clothArmor, 32, 256, 32, 32);
sprite = new Sprite(region);
sprite.setOrigin(0.5f, 0.5f);
sprite.setPosition(0f - 0.5f, 0f);
sprite.setSize(2, 2);
// Setup player and associated animations
Array<TextureRegion> regions = new Array<TextureRegion>();
player = new Player();
}
@Override
public void dispose() {
spriteBatch.dispose();
texture.dispose();
clothArmor.dispose();
spriteSheet.dispose();
}
@Override
public void render() {
player.update(Gdx.graphics.getDeltaTime());
camera.update();
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) {
Gdx.app.exit();
}
// Clear the last cell
layer.setCell(hoverTileX, hoverTileY, null);
// Convert screen coordinates to world coordinates
Vector3 worldCoordinates = new Vector3(Gdx.input.getX(0), Gdx.input.getY(0), 0);
camera.unproject(worldCoordinates);
hoverTileX = (int)(worldCoordinates.x);
hoverTileY = (int)(worldCoordinates.y);
TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get("collision");
if(Gdx.input.isTouched(0)) {
//sprite.setPosition(hoverTileX - 0.5f, hoverTileY);
player.pos.x = hoverTileX - 0.5f;
player.pos.y = hoverTileY - 0.25f;
cell.setTile(animatedGoTile);
} else {
if (layer.getCell(hoverTileX, hoverTileY) != null) {
cell.setTile(cannotMoveToTile);
} else {
cell.setTile(canMoveToTile);
}
}
layer.setCell(hoverTileX, hoverTileY, cell);
mapRenderer.setView(camera);
mapRenderer.render();
mapRenderer.getSpriteBatch().begin();
mapRenderer.renderTileLayer(layer);
mapRenderer.getSpriteBatch().end();
spriteBatch.setProjectionMatrix(camera.combined);
spriteBatch.begin();
player.render(spriteBatch);
spriteBatch.end();
}
@Override
public void resize(int width, int height) {
horizontalTiles = (float) width/(float) height * verticalTiles;
camera = new OrthographicCamera(horizontalTiles, verticalTiles);
w = width;
h = height;
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}
привет, добро пожаловать в переполнение стека! Пожалуйста, добавьте свое «обновление» в качестве ответа на свой вопрос. Как новый пользователь, это может быть немного заблокировано, но в конечном итоге это возможно. Благодаря! См. Http://stackoverflow.com/help/self-answer –