如何在Libgdx中渲染交替的精灵以实现无限背景?

时间:2015-11-03 16:28:43

标签: android libgdx rendering sprite

我正在尝试在Libgdx中编写一个具有滚动背景的程序。 我尝试滚动背景的方式如下:

//creating two sprites whose size is the 2*viewportwidth
//this shows half of the sprite on my phone screen
//which I assume that it takes two viewport widths to show the entire sprite
sprite1;
sprite2;
//setting the positions which shows the sprites next to each other
sprite1.setPosition(0f,0f);
sprite2.setPosition(2f*viewportwidth,0);
//on to my render method, I have the following besides the usual:

@Override
public void render(){
//usual stuff here
camera.update
camera.setProjectionMatrix(camera.combined);

batch.begin();
sprite1.draw(batch);
sprite2.draw(batch);
batch.end();

moveCammy();

}

private void moveCammy(){

if(System.currentTimeMillis()-time>1000){
moviX=moviX+0.1*camera.viewportWidth;//moviX is a float
camera.translate(moviX,0f);
time= System.currentTimeMillis();

if(System.currentTimeMillis()-time2>22000){
sprite1.setX(4f*camera.viewportWidth)//since each phone screen width 
//represents half of each sprite. It takes two phone screens to show 
//one sprite. Since, originally there were two sprites it takes 4 phone 
//screens to show them side by side.However, third sprite doesn't appear 
//right after the second sprite. I think it should since it's 4 phone 
// screens away. I assume the translation of the camera is around the second
//sprite after about 220000 milliseconds. 

time2= System.currentTimeMillis();}

}

除了没有出现第三个精灵外,程序中的一切都有效 一点都不我的目标是无限地保持交替的sprite1和sprite2来实现 无限的背景。

请告知可能出现的问题。

0 个答案:

没有答案