Java 平铺贴图编辑器在libgdx中的所有其他内容之上进行渲染
我开始使用平铺地图编辑器作为新游戏的编辑器。(这是一台平板电脑)。因此,我创建了平铺贴图并将其保存为.tmx文件。地图很简单,我只是用它来测试一下。在我的代码中,我只是在屏幕上呈现了一个五角大楼作为“玩家”对象。当我在地图中添加此代码时:Java 平铺贴图编辑器在libgdx中的所有其他内容之上进行渲染,java,libgdx,tile,Java,Libgdx,Tile,我开始使用平铺地图编辑器作为新游戏的编辑器。(这是一台平板电脑)。因此,我创建了平铺贴图并将其保存为.tmx文件。地图很简单,我只是用它来测试一下。在我的代码中,我只是在屏幕上呈现了一个五角大楼作为“玩家”对象。当我在地图中添加此代码时: package com.thechief.platformer.states; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.maps.tiled.Tile
package com.thechief.platformer.states;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector2;
import com.thechief.platformer.Gradual;
import com.thechief.platformer.entities.Player;
import com.thechief.platformer.textures.TextureManager;
public class GameState extends State {
public static final float GRAVITY = 15f;
private Player player;
private TmxMapLoader maploader;
private TiledMap map;
private OrthogonalTiledMapRenderer renderer;
@Override
public void create() {
setUp();
camera.setToOrtho(false, Gradual.WIDTH, Gradual.HEIGHT);
player = new Player(new Vector2(camera.position.x, camera.position.y));
maploader = new TmxMapLoader();
map = maploader.load("map.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
camera.update();
}
@Override
public void update(float dt) {
player.update(dt);
}
@Override
public void render(SpriteBatch sb) {
sb.setProjectionMatrix(camera.combined);
sb.begin();
renderer.setView(camera);
renderer.render();
player.render(sb);
sb.end();
}
@Override
public void dispose() {
renderer.dispose();
map.dispose();
}
}
地图渲染,但玩家不渲染!
下面是Player.java
类:
package com.thechief.platformer.entities;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Vector2;
import com.thechief.platformer.textures.TextureManager;
public class Player extends Entity {
private float spd = 4;
private float velX = 0, velY = 0;
public Player(Vector2 pos) {
super(TextureManager.pentagon, pos);
}
@Override
public void update(float dt) {
if (Gdx.input.isKeyPressed(Keys.D) || Gdx.input.isKeyPressed(Keys.RIGHT)) {
pos.x += spd;
}
if (Gdx.input.isKeyPressed(Keys.A) || Gdx.input.isKeyPressed(Keys.LEFT)) {
pos.x -= spd;
}
pos.x += velX;
pos.y += velY;
}
}
为什么会这样?我是不是在代码中做错了什么?
或者玩家类有什么问题吗?我不这么认为,因为即使我替换了player.render(sb)使用sb.draw(TextureManager.pentage,x,y)
它仍然不会渲染。
请帮忙
提前谢谢 你在哪儿玩?是不是丢失了?播放器的渲染方法在哪里?哎呀!我不小心做了调试!(它仍然不能与render方法一起工作)大多数代码都是抽象的,比如状态
和实体
类,甚至播放器的render()
?是的。update(float dt)和render(sb)在state和entity类中。它们是抽象的。哦,很抱歉,实体类中的render方法不是抽象的。它只是执行sb.draw(纹理、位置x、位置y、宽度、高度)代码>