【问题标题】:Draw part of texture in AndEngine在AndEngine中绘制部分纹理
【发布时间】:2014-03-12 12:44:54
【问题描述】:

所以我使用 ligbdx 已经有一段时间了,做这样的事情真的很简单。所以我想要实现的是,当我有一个大纹理时,我想通过给出 x,y(从哪里开始切割)和宽度,高度(切割部分的大小)来获得该纹理的一部分,然后使用它部分作为精灵或任何可以在 andengine 场景中绘制的东西。

在 libgdx 中是这样的:

//loads file from assets into texture
Texture texture = new Texture(Gdx.files.internal("data/texture5.png")); 

//cuts a part of it into drawable element
TextureRegion part = new TexureRegion(texture, x, y, width, height); 

部分只是我稍后需要在屏幕上绘制的那部分纹理。在 andengine 中做真的很难,以至于在互联网上的任何地方我都找不到 2 小时的搜索答案吗? :)

【问题讨论】:

    标签: android andengine sprite


    【解决方案1】:

    我刚刚搜索了几个小时,却一无所获。但我不小心尝试了这个,它奏效了。这是一个老问题,但无论如何。也许这会有所帮助。

        ITexture texture = null;
        try {
            texture = new BitmapTexture(engine.getTextureManager(),
                    new IInputStreamOpener() {
    
                        public InputStream open() throws IOException {
                            return engine.getAssets().open(path);
                        }
                    });
    
            texture.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        ITextureRegion texturePart = new TextureRegion(texture, x, y, width, height);
    

    【讨论】:

      猜你喜欢
      • 2013-10-22
      • 2012-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-23
      • 1970-01-01
      • 2016-11-07
      相关资源
      最近更新 更多