[英]Libgdx Scrolling TiledMaps
i'm trying to make my libgdx map scroll, but i dont know the code to make map scroll, please guys help me, i would like the map to scroll like flappy bird game, this is my my code which show the map on the screen 我正在尝试使我的libgdx地图滚动,但是我不知道使地图滚动的代码,请大家帮我,我希望地图像飞扬的小鸟游戏一样滚动,这是我的代码,在屏幕
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
position.y = position.y - 4;
if(Gdx.input.isTouched()){
position.y = position.y +10;
}
if(position.y < 0){
position.y = 0;
}
if(position.y > Gdx.graphics.getHeight() -70){
position.y = Gdx.graphics.getHeight() - 70;
}
renderer.setView(camera);
renderer.render();
//tells the computer when to start drawing textures
batch.begin();
batch.draw(Green1, position.x, position.y, 50, 50);
batch.end();
}
@Override
public void show() {
Green1 = new Texture("img/Green1.png");
batch = new SpriteBatch();
position = new Vector2(20, Gdx.graphics.getHeight());
map = new TmxMapLoader().load("maps/map1.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
camera = new OrthographicCamera();
}
@Override
public void hide() {
}
@Override
public void create() {
Green1 = new Texture("img/Green.png");
batch = new SpriteBatch();
position = new Vector2(20, Gdx.graphics.getHeight());
}
@Override
public void resize(int width, int height) {
camera.viewportWidth = width;
camera.viewportHeight = height;
camera.position.set(width/2f, height/3f, 0); //by default camera position on (0,0,0)
camera.update();
}
@Override
public void render() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
map.dispose();
renderer.dispose();
}
} }
When I was learning to build 2D games I used star-assault for an example. 当我学习制作2D游戏时,我以星际突击为例。 You can find their github repository here: https://github.com/chrismorales/2d-sidescroller && https://github.com/chrismorales/2d-sidescroller/blob/master/star-assault/src/net/obviam/starassault/view/WorldRenderer.java should be useful to look at. 您可以在这里找到他们的github存储库: https : //github.com/chrismorales/2d-sidescroller && https://github.com/chrismorales/2d-sidescroller/blob/master/star-assault/src/net/obviam/ starassault / view / WorldRenderer.java应该很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.