【发布时间】:2015-05-28 22:02:53
【问题描述】:
我让我的相机沿 x 轴滚动,当我的地板对象离开屏幕时,我在屏幕边界之外添加一个新的地板对象并移除离开视图的旧地板对象。
当且仅当我移除对象时,它会导致该数组中的其他对象闪烁
这里是删除注释掉的代码。
batch.begin()
for(GameObject pillar: pillars) {
pillar.draw(batch);
if(pillar.getBounds().getX() + 64 < camera.position.x - SCREEN_WIDTH/2) {
//pillars.removeValue(pillar, false);
}
}
batch.end()
这是另一个我也添加到数组中的示例
for(GameObject ceiling: ceilings) {
ceiling.draw(batch, SCREEN_WIDTH, CEILING_HEIGHT);
if((ceiling.getBounds().getX() + ceiling.getBounds().getWidth()) < (camera.position.x - SCREEN_WIDTH/2)) {
ceilings.add(new GameObject(boundsTexture, ceiling.getBounds().getX() + (ceiling.getBounds().getWidth()*2),SCREEN_HEIGHT - CEILING_HEIGHT, false));
//ceilings.removeValue(ceiling, false);
}
}
这是 GameObject 类
public class GameObject {
protected Vector2 location;
private Rectangle bounds;
protected Texture frame;
protected TextureRegion currentFrame;
GameObject(Texture texture, float xLocation, float yLocation, boolean flippedV) {
frame = texture;
location = new Vector2(xLocation, yLocation);
bounds = new Rectangle( location.x, location.y,
frame.getWidth(),
frame.getHeight());
currentFrame = new TextureRegion(frame, 0, 0, 64, 64);
if(flippedV) {
currentFrame.flip(false, true);
}
}
public void draw(SpriteBatch batch) {
batch.draw(currentFrame, location.x, location.y);
}
public void draw(SpriteBatch batch, float width, float height) {
batch.draw(currentFrame, location.x, location.y, width, height);
}
public Rectangle getBounds() {
return bounds;
}
}
我应该提到我正在使用 deltaTime 移动相机,没有其他移动, 相机是正交的。
camera.translate(300*delta,0);
我也试过
camera.translate((int)300*delta,0);
【问题讨论】:
-
我修好了,我把添加和删除的代码从... batch.begin();批处理.end();
-
在这里发布您的修复作为您问题的答案。这将帮助其他有类似问题的人。谢谢
-
我这样做了,但我不能接受 2 天的答案
-
感谢您发布答案
标签: java arrays libgdx textures flicker