【问题标题】:Getting blank line when moving background image (Andengine)移动背景图像时获取空白行(Andengine)
【发布时间】:2012-09-27 08:24:56
【问题描述】:

我正在使用 andengine 开发游戏..我使用 AutoParallaxBackground 移动背景图像..它工作正常..但图像之间有一个空白行..图像没有问题

ie: autoParallaxBackground.addParallaxEntity(new ParallaxEntity(-20.0f, new Sprite(0, 0, this.bgTextureRegion1)));

如何解决这个问题?

设备屏幕截图...左角可见空白行

图像尺寸:720x480 相机尺寸:720x480 手机屏幕尺寸:320x240

【问题讨论】:

    标签: android andengine


    【解决方案1】:

    问题是由于在应用双线性过滤时 TextureAtlas 的黑色背景渗入图像造成的。解决方案是将最左边和最右边的 1px 线加倍,使出血具有正确的颜色。这是一个令人讨厌的修复,应该证明这确实是问题所在,但是它将加载背景所需的时间增加了三倍,因此它对生产代码没有用处。当您为背景创建 TextureAtlas 时,请执行以下类似操作:

    BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundBitmapTexture, this, "background.png", 0, 0);
    BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundBitmapTexture, this, "background.png", 2, 0);
    this.backgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundBitmapTexture, this, "background.png", 1, 0);
    

    它的作用是加载纹理三次,前两次左右移动一个像素。第三个调用在两者之间创建实际的纹理区域。

    【讨论】:

    • 是的。现在问题已解决。它工作正常。但同样认为重复 3 次..它会花费更多的加载时间? ...我在游戏中使用了 4 个背景图像
    • 是的,这样做会增加加载时间,这只是一个测试,看看你是否有我所说的问题。更正确的方法是从背景中提取 1px 线作为单独的图像,然后加载那个小图片。更好的办法是访问纹理并通过 OpenGL 完成,但我的功夫还不够强大:-) 这能回答你的问题吗?
    • 是的.. 提取答案.. 但是如何以及在何处从背景图像中放置 1px 线..
    【解决方案2】:

    双线性纹理选项正是问题所在。在 GLES2.0 中,您可以删除 TextureOptions.BILINEAR,也可以将其更改为 NEAREST_PREMULTIPLYALPHA。

    【讨论】:

      【解决方案3】:

      为您的背景精灵实现 preDraw() 方法并设置 pGLState.enableDither();

      new Sprite(0, CAMERA_HIGHT,
                          this.mParallaxLayerBack, vertexBufferObjectManager) {
      
                      @Override
                      protected void preDraw(GLState pGLState, Camera pCamera) {
      
                          super.preDraw(pGLState, pCamera);
                          pGLState.enableDither();
                      }
      
                  }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-11-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多