简体   繁体   English

使用Slick2D滚动背景

[英]Scrolling Background with Slick2D

Full source of what I'm trying to do can be found here 我想做的事情的完整资料可以在这里找到

I am trying to make a background scroll as mentioned above, I have made progress to the point where it is infinite, but it seems to disappear mid way through. 我正在尝试使背景滚动如上所述,我已经取得了进展,直到达到无限远,但似乎在中途消失了。 I am currently stuck and have no idea how to progress from this point. 我目前陷入困境,不知道如何从这一点开始。

You can demo this by cloning the git provided above into eclipse. 您可以通过将上面提供的git克隆到eclipse中来进行演示。 It should work on the fly without any setup needed. 它无需任何设置即可即时运行。 The canvas size is 1000 by 720. 画布大小为1000 x 720。

int bgend=-(1000-bg.getWidth());
public void update(int delta){
    x-=delta*0.2;
    nx-=delta*0.2;
    if(x<=bgend&&x>=-bgend+delta*0.2){nx=1000;}
    else if(nx<=bgend&&nx>=-bgend+delta*0.2){x=1000;

    }

This is the logic associated with the scrolling. 这是与滚动相关的逻辑。 Then these values are used to render the image, 然后,这些值将用于渲染图像,

public void render(Graphics g){

bg.draw(x, y, bg.getWidth(), 720);

bg.draw(nx, y, bg.getWidth(), 720);


}

All of this is also in the link provided. 所有这些都在提供的链接中。 Thank you. 谢谢。

Can i know the size of the picture and the size of the screen ?! 我能知道图片的尺寸和屏幕的尺寸吗? I think maybe u need to "cut" the image in the render method depend on how much u scrolled down/up in the state.. let me be more cleary using bottons: lets assume that every "W" is 1 pixel up and every "S" is 1 pixel down in "y" axis ,the pic is 1000 pixels hight and the state is set to 500 pixel hight ,and lets assume that we start from the bottom of the that photo so we need to get higher ,so every W push we update a param "UP" in the update method and then in the render method we cut the photo using "IMAGE.getSubImage(XstartPoint,YstartPoint,hight,width)".. i hope that was useful to you mate. 我认为也许您需要在render方法中“剪切”图像取决于您在状态下向下滚动/向上滚动的程度..让我更清楚地使用bottons:假设每个“ W”向上1像素,每个“ S”在“ y”轴上向下移动1个像素,图片高度为1000像素,状态设置为高度500像素,并假设我们从该照片的底部开始,因此我们需要将其提高每次W推时,我们都会在update方法中更新参数“ UP”,然后在render方法中使用“ IMAGE.getSubImage(XstartPoint,YstartPoint,hight,width)”剪切照片。我希望这对您交配很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM