如何在自上而下的游戏中扩展LibGdx的背景?

时间:2017-03-16 02:17:36

标签: java android libgdx vertical-scrolling top-down

在自上而下游戏中扩展背景的正确方法是什么?我使用了LibGdx框架。自上而下游戏的任何想法或教程。我的背景是PNG格式和720x1280肖像的屏幕。我有一个问题,在扩展背景。我希望相机跟随角色,背景将延伸。我怎么能这样做?这是

的屏幕截图

https://i.stack.imgur.com/jl03R.png

这是我的代码

显示我用过的背景

    //background
    Background = new Texture(Gdx.files.internal("floor.png")); //File from assets folder
    Background.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
    bgsprite = new Sprite(Background);

在渲染中

 spriteBatch.draw(Background,0,100,0, srcy, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
    srcy +=3;

背景是滚动但摄像机不跟随播放器(猫)

GameScreen的源代码  http://pastebin.com/Dxfx9f65

感谢&并且提前任何帮助或建议非常感谢。 :)

1 个答案:

答案 0 :(得分:1)

使用两个相同的纹理背景。每个屏幕的大小它可以是同一个文件。垂直停靠很重要。同时移动。交替改变彼此。 示例代码:

声明:

import os
import django
from django.core.files import File

django.setup()

from gallery.models import Image    

path = r"C:\Users\admin\Pictures"

for filename in os.listdir(path):
    filePath = os.path.join(path, filename)
    thisFile = File(open(filePath, 'rb'))
    new_img = Image(original=thisFile, title=filename)
    new_img.save()

创建:

Texture background1, background2;
SpriteBatch batch;
float yMax, yCoordBg1, yCoordBg2;
final int BACKGROUND_MOVE_SPEED = 100; // pixels per second. Put your value here.
方法渲染中的

Background1 = new Texture(Gdx.files.internal("floor.png"));
Background2 = new Texture(Gdx.files.internal("floor.png")); // identical 
yMax = 1280;
yCoordBg1 = yMax*(-1); yCoordBg2 = 0;

背景可以用jpg格式制作 - 将花费更少的内存。

相关问题