Java Libgdx二维地板动画
我正在打造跑步者游戏。 地面级Java Libgdx二维地板动画,java,android,libgdx,Java,Android,Libgdx,我正在打造跑步者游戏。 地面级 public class Ground extends Actor { private Texture texture; private ArrayList<Vector2> groundLocations; private float speed; private float cameraLeft, cameraRight; private int textureWidth; public Ground() { this.cameraR
public class Ground extends Actor {
private Texture texture;
private ArrayList<Vector2> groundLocations;
private float speed;
private float cameraLeft, cameraRight;
private int textureWidth;
public Ground() {
this.cameraRight = Const.GAME_WIDTH + Const.GAME_MARGIN;
this.cameraLeft = 0 - Const.GAME_MARGIN;
texture = new Texture(Gdx.files.internal("ui/ground.png"));
groundLocations = new ArrayList<Vector2>();
init();
}
public void setSpeed(float speed) {
this.speed = speed;
}
private void init() {
textureWidth = texture.getWidth();
float currentPosition = cameraLeft;
while (currentPosition < cameraRight) {
Vector2 newLocation = new Vector2(currentPosition, 0);
groundLocations.add(newLocation);
currentPosition += textureWidth;
}
}
public int getFloorHeight() {
return texture.getHeight();
}
@Override
public void act(float delta) {
super.act(delta);
int size = groundLocations.size();
for (int i = 0; i < size; i++) {
Vector2 location = groundLocations.get(i);
location.x -= delta * speed;
if (location.x < cameraLeft) {
location.x = findMax().x + textureWidth;
}
}
}
private Vector2 findMax() {
return Collections.max(groundLocations, new Vector2Comparator());
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
for (Vector2 location : groundLocations) {
batch.draw(texture, location.x, location.y);
}
}
public void dispose() {
if (texture != null)
texture.dispose();
}
public类扩展了Actor{
私有纹理;
私人ArrayList地面位置;
私人浮动速度;
私人浮标照相机;
私有int纹理宽度;
公共场所{
this.cameraRight=Const.GAME\u WIDTH+Const.GAME\u MARGIN;
this.cameraLeft=0-Const.GAME_边距;
纹理=新纹理(Gdx.files.internal(“ui/ground.png”);
groundLocations=newarraylist();
init();
}
公共无效设置速度(浮动速度){
速度=速度;
}
私有void init(){
textureWidth=texture.getWidth();
浮动电流位置=相机左移;
while(当前位置<相机右){
Vector2 newLocation=新Vector2(当前位置,0);
groundLocations.add(newLocation);
currentPosition+=纹理宽度;
}
}
public int getFloorHeight(){
返回texture.getHeight();
}
@凌驾
公共无效法案(浮动三角洲){
超级法案(德尔塔);
int size=groundLocations.size();
对于(int i=0;i
}
- 地面纹理为128x128
- 游戏宽度=1024f
- 游戏保证金=250f
- 速度=变化
哇,简直不敢相信我居然没看到
for (int i = 0; i < size; i++) {
Vector2 location = groundLocations.get(i);
if (location.x < cameraLeft) {
location.x = findMax().x + textureWidth;
}
location.x -= delta * speed;
}
for(int i=0;i
哇,真不敢相信我居然没看到
for (int i = 0; i < size; i++) {
Vector2 location = groundLocations.get(i);
if (location.x < cameraLeft) {
location.x = findMax().x + textureWidth;
}
location.x -= delta * speed;
}
for(int i=0;i
地面纹理之间的间隙是什么意思?我们可以看到问题的图像吗?更新添加的图像..地面纹理之间的间隙是什么意思?我们可以看到问题的图像吗?更新添加的图像。。