Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在Libgdx中渲染交替精灵以实现无限背景?_Android_Libgdx_Rendering_Sprite - Fatal编程技术网

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

Android 如何在Libgdx中渲染交替精灵以实现无限背景?,android,libgdx,rendering,sprite,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; //setti

我正在尝试用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无限交替以实现 无限的背景


请告知可能的错误。

您能发布项目中的实际代码吗?缺少右括号和分号,并且不存在名为(
camera.setProjectionMatrix
的方法),这使得很难看到错误是什么。它看起来有点像你每秒只移动一次你的相机,它正在加速。为什么你们要根据时间而不是相机的位置来移动精灵呢?阅读下面的问题,我认为在LIBGDX中使用parralax可能会对ypu有所帮助