我想让png到textureRegions并在一些搜索之后我感到困惑。有人说我必须使用纹理,其他纹理阿特拉斯,其他人使用bitmapTextureAtlas等。 所以任何人都可以告诉我如何做到这一点,从创建必须创建的东西到让textuReregion在我需要的任何地方都可用。 我完全混淆所以请详细说明!感谢。
纹理构造函数
a = new ITexture() {
@Override
public int getWidth() {
return 0;
}
@Override
public int getHeight() {
return 0;
}
@Override
public int getHardwareTextureID() {
return 0;
}
@Override
public boolean isLoadedToHardware() {
return false;
}
@Override
public void setNotLoadedToHardware() {
}
@Override
public boolean isUpdateOnHardwareNeeded() {
return false;
}
@Override
public void setUpdateOnHardwareNeeded(boolean pUpdateOnHardwareNeeded) {
}
@Override
public void load() {
}
@Override
public void load(GLState pGLState) throws IOException {
}
@Override
public void unload() {
}
@Override
public void unload(GLState pGLState) {
}
@Override
public void loadToHardware(GLState pGLState) throws IOException {
}
@Override
public void unloadFromHardware(GLState pGLState) {
}
@Override
public void reloadToHardware(GLState pGLState) throws IOException {
}
@Override
public void bind(GLState pGLState) {
}
@Override
public void bind(GLState pGLState, int pGLActiveTexture) {
}
@Override
public PixelFormat getPixelFormat() {
return null;
}
@Override
public TextureOptions getTextureOptions() {
return null;
}
@Override
public boolean hasTextureStateListener() {
return false;
}
@Override
public ITextureStateListener getTextureStateListener() {
return null;
}
@Override
public void setTextureStateListener(ITextureStateListener pTextureStateListener) {
}
}
答案 0 :(得分:0)
我不确定我清楚地了解您的问题是什么,但如果您想加载.png图片,就可以这样做了。
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
AddTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(),
256, 256, TextureOptions.BILINEAR);
Add_region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
AddTextureAtlas, activity, "add.png", 0, 0);
AddTextureAtlas.load();
你就像这样附上它
Sprite mySprite = new Sprite(0, 0,
ResourcesManager.getInstance().Add_region,
ResourcesManager.getInstance().vbom);
attachChild(mySprite);
我使用单独的Resources管理器类来加载纹理。其中gfx是资产中的文件夹
答案 1 :(得分:0)
一步一步:
编码。使用加载纹理的方法有一些ResourceManager类是个好主意。让我们说你创建一个。其中一个(即loadExamplePNG()
:
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
- 这会为您的图片设置defoult文件夹(您不必使用它,但之后您必须将路径放到图像中)
BitmapTextureAtlas exampleTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(),
256, 256);
- 纹理图集就像一张纸上贴有纸。您可以创建大图集来放置图像/纹理并将它们加载到一起。数字256,256表示你的地图集有多大。它们必须是2的幂(256,512,1024,2048)。有些手机不能超过1024 x 1024。
ITextureRegion exampleTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
exampleTextureAtlas, activity, "example.png", 0, 0);
- 在这里,我们将图像放在地图上,就像纸上的贴纸一样。你选择你的形象" example.png"并将其放在exampleTextureAtlas
的位置(0,0)。您可以在地图册中放置多个区域,但不能选择相同的坐标。因此,如果第一个区域位于(0,0)位置并且它是100x100大 - 则第二个图像必须位于例如位置(110,0),因此它们不会重叠。
exampleTextureAtlas.load();
- 最后我们加载了地图集。简单。Aslo,正如@mayurN指出的那样:如果你将这段代码放在resourceManager的方法中(作为单例模式类),你可以将它用作:
ResourceManager.getInstance().loadExamplePNG();