java - 如何从andEngine GLES2中的 Sprite 表中获取特定的 Sprite ?

标签 java android andengine

我的 Sprite 表没有按行和列进行管理。但我有 Sprite 表中每个 Sprite 的像素坐标、高度和宽度。据我所知,我应该能够通过

获得一张特定的图像
    spaceshipTexture = new BitmapTextureAtlas(getTextureManager(),1024,512,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    playerTextureRegion= BitmapTextureAtlasTextureRegionFactory.createFromAsset(spaceshipTexture, 
            this, "spaceshipsheet.png",0,119);

这里我提供了 Sprite 的 x 坐标和 y 坐标作为 createFromAsset 函数的最后两个参数。它不应该返回位于 Sprite 表中该坐标的特定图像吗?相反,它会将整个 Sprite 归还给我。如果我没有正确获得该功能,请解释一下最后两个参数的含义是什么?我怎样才能获得特定的 Sprite ?帮助我,我是 andEngine 的新手。

最佳答案

由于您的 spritesheet 不是行或列管理的,您将无法从允许您设置行号和列号的 BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset 中受益。

但是,我的处境与您相同,所以这就是我所做的(使用您的代码)。

spaceshipTexture = new BitmapTextureAtlas(getTextureManager(), 1024, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

playerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(spaceshipTexture, 
        this, "spaceshipsheet.png", 0, 0); // start reading from the start of your spritesheet, so you can set multiple sprites

playerTextureRegion.set(0, 109, 20, 20); // pTextureX, pTextureY, pTextureWidth, pTextureHeight -- here you grab the sprite from the spritesheet

最后两个参数(来自您最初的问题)是 pTextureX 和 pTextureY,它们设置从 spritesheet 开始读取的位置。这就是为什么你仍然得到所有东西的原因。

希望这有帮助。

关于java - 如何从andEngine GLES2中的 Sprite 表中获取特定的 Sprite ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33498741/

相关文章:

java - 如何提取 <a> 超链接标记之间的文本

java - SVG如何在Java中使用平移和旋转获取变换的绝对坐标

android - 具有自定义布局和自定义菜单项的 ActionBar

android - AndEngine 示例不工作

java - Andengine 多人扩展 make 抛出错误,但在 Intellij IDEA 编辑器窗口中不显示

java - 需要 Spring 服务、存储库、实体设计模式建议

wicket 1.5 中的 javascript 引用顺序

java - 有没有办法覆盖 BufferedReader 使用的行结尾?

android - 蓝色全息颜色在设备上显示为绿色

android - 如何在andengine中移动线的终点