Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AndEngine SpriteBatch setColor()不工作_Java_Android_Sprite_Andengine - Fatal编程技术网

Java AndEngine SpriteBatch setColor()不工作

Java AndEngine SpriteBatch setColor()不工作,java,android,sprite,andengine,Java,Android,Sprite,Andengine,我正在写一个游戏,我把几十个精灵放在一个SpriteBatch里。这需要做,否则帧速率会急剧下降,当我画每一个精灵自己。 我的问题是,如何更改完整SpriteBatch的颜色 以下是我创建SpriteBatch的方式: 使用spriteBatch带来了更多的性能,因此,对我来说,将ArrayList与所有原始Sprite保持在一起并每次重新初始化批处理仍然足够快。但是,当有人成功地扩展了SpriteBatch类时,我当然会非常感兴趣!:) 尽管SpriteBatch有一个setColor(),但

我正在写一个游戏,我把几十个精灵放在一个SpriteBatch里。这需要做,否则帧速率会急剧下降,当我画每一个精灵自己。 我的问题是,如何更改完整SpriteBatch的颜色

以下是我创建SpriteBatch的方式:


使用spriteBatch带来了更多的性能,因此,对我来说,将ArrayList与所有原始Sprite保持在一起并每次重新初始化批处理仍然足够快。但是,当有人成功地扩展了SpriteBatch类时,我当然会非常感兴趣!:)

尽管SpriteBatch有一个setColor(),但这实际上只是它扩展形状的产物。两种可能的解决办法:

(1)分别为每个雪碧上色。

ArrayList<Sprite> dozenSprites; // these are all the sprites of one SpriteBatch in a list
SpriteBatch spriteBatch = new SpriteBatch(spriteBatchTextureAtlas, dozenSprites.size(),vertexBufferObjectManager);

for (Sprite sprite : dozenSprites) {
        sprite.setColor(.5f, .5f, .5f);
        spriteBatch.draw(sprite);
}
spriteBatch.submit();       
arraylistdozensprites;//这些是列表中一个SpriteBatch的所有精灵
SpriteBatch SpriteBatch=新的SpriteBatch(spriteBatchTextureAtlas,dozenSprites.size(),vertexBufferObjectManager);
用于(精灵精灵:dozenSprites){
设置颜色(.5f、.5f、.5f);
spriteBatch.draw(精灵);
}
spriteBatch.submit();
(2)在AndEngine中修改SpriteBatch

如果您真的不想给每个精灵上色,那么在AndEngine中修改SpriteBatch类并添加一个覆盖setColor()的方法怎么样。向spritebatch添加颜色字段,让setcolor调整该字段,然后在draw方法中,让spritebatch将其绘制的精灵的颜色设置为其存储的颜色字段


如果您在AndEngine中干净地实现了它,您甚至可以将其作为源代码的可能更改提交。(这是开源的。参与其中很有趣。)

谢谢!我将尝试找出如何修改spritebatch,使其具有颜色字段。如果我不能,我可能不得不使用(1)。。但至少我知道我现在的立场,谢谢。
 // initialize the SpriteBatch as above
 // and to change the color call:
 spriteBatch.reset();
 for (Sprite sprite : dozenSprites) {
        sprite.setColor( theNewColor );
        spriteBatch.draw(sprite);
 }
 spriteBatch.submit();
ArrayList<Sprite> dozenSprites; // these are all the sprites of one SpriteBatch in a list
SpriteBatch spriteBatch = new SpriteBatch(spriteBatchTextureAtlas, dozenSprites.size(),vertexBufferObjectManager);

for (Sprite sprite : dozenSprites) {
        sprite.setColor(.5f, .5f, .5f);
        spriteBatch.draw(sprite);
}
spriteBatch.submit();