2015-11-03 65 views
0

我有精灵表,这不是管理行和列明智。但是我有像素坐标,精灵表中每个精灵的高度和宽度。我到目前为止,我是知道我应该能够通过如何从andEngine GLES2中的sprite表中获取特定的Sprite?

spaceshipTexture = new BitmapTextureAtlas(getTextureManager(),1024,512,TextureOptions.BILINEAR_PREMULTIPLYALPHA); 
    playerTextureRegion= BitmapTextureAtlasTextureRegionFactory.createFromAsset(spaceshipTexture, 
      this, "spaceshipsheet.png",0,119); 

在这里,我已经提供了在createFromAsset功能精灵作为最后两个参数的x cordinate和y cordinate得到一个特定的图像。它不应该返回位于精灵表中该坐标中的特定图像吗?相反,它会让我看到整个精灵。如果我没有正确地获得该功能,请解释我最后两个参数的含义是什么?我怎样才能得到一个特定的精灵?帮助我,我只是刚接触和引擎。

回答

0

程序是: 设置纹理图集 - 完成; 设置纹理区域 - 完成//想象它们作为纸张上的贴纸,可以有很多,只要记住它们不能重叠,或者越过图册

现在它的简单: 你设置你的精灵是这样的:

Sprite yourSprite = new Sprite(x, y, playerTextureRegion, vertexBufferObjectManager); 

正如你可以看到你把你的textureregion作为construcotr的parametr。这样你就不必为纹理区域设置任何坐标。

还记得你的精灵附着到现场:

mScene.attachChild(yourSprite); 
+0

我明白你在说什么是Lukasz,但我想有一个单独的spritesheet而不是单独的精灵(他们使用大量的内存,即使我的简单游戏是巨大的大小),所以,我把所有的精灵放在一张单通过一个名为sprite packer的软件,它会生成一个文本文件,其中包含工作表中各个精灵的坐标,宽度和高度。他们不是现在以行和列的大小进行管理的,我想使用该工作表中的特定精灵。我知道如何创建一个精灵,我只是不知道该如何引用该工作表中的精灵精灵。帮助 – willnotquit

+0

哦,全部对。这可能会帮助你:http://www.matim-dev.com/texture-packer.html –

1

因为你的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阅读。这就是为什么你仍然会把所有东西都还给你。

希望这会有所帮助。

+0

繁荣,这工作!非常感谢sij_a你摇滚... – willnotquit

+0

没问题!很高兴它的工作。如果您对此感到满意,请将此标记为接受的答案:) –