Android 如何在Libgdx二维动画中获得最佳性能?
我有一个由9张图片组成的纹理包。 在9幅图像中,我使用了其中3幅作为动画帧。因此,我的动画由3个图像组成。 这些图像的固定分辨率为128x128Android 如何在Libgdx二维动画中获得最佳性能?,android,performance,libgdx,Android,Performance,Libgdx,我有一个由9张图片组成的纹理包。 在9幅图像中,我使用了其中3幅作为动画帧。因此,我的动画由3个图像组成。 这些图像的固定分辨率为128x128 TextureRegion sprite1 = atlas.findRegion("sprite1"); TextureRegion sprite2 = atlas.findRegion("sprite2"); TextureRegion sprite3 = atlas.findRegion("sprite3"); ... ... Animatio
TextureRegion sprite1 = atlas.findRegion("sprite1");
TextureRegion sprite2 = atlas.findRegion("sprite2");
TextureRegion sprite3 = atlas.findRegion("sprite3");
...
...
Animation spriteAnimation = new Animation(.130f,new TextureRegion[sprite1,sprite2,sprite3]);
// similarly I am creating 4 more animation instance using same 3 regions
Animation spriteAnimation2 = new Animation(.130f,new TextureRegion[sprite1,sprite2,sprite3]);
...
...
游戏循环:-
{
update();
render();
}
我在update()
和render()
中有以下代码
现在,update()
方法平均需要0.045ms,而render()
方法平均需要16ms,使我的FPS为~60
在某个瞬间,render()。渲染方法每帧的工作负载相同,即渲染5个动画
我是libgdx新手,之前没有任何游戏经验
我可以知道我在实现动画时犯了什么错误吗
update()
代码对我来说运行得很好,但是看起来render()
中有严重的漏洞,这听起来很普通,在屏幕上绘制东西比其他任何东西都要花费更长的时间。谢谢@sulthan的编辑。。!后端限制了FPS:因此如果您使用lwjgl后端,您将不会像我一样超过60 FPSunderstood@Springrbua这是不对的。你发布的维基完全过时了。请参阅此帖子:。后端具有禁用最大fps的选项。但是android后端不允许您禁用vsync@BennX这应该是正确的,因为根据我的理解,默认情况下限制是打开的。我发布的wiki也告诉你,你可以禁用它。它可能已经过时了,但是没有链接到这个主题的新wikipost,我不认为它完全改变了。。。所以他可能有限制。如果我错了,请纠正我,我是来学习的:)
update()
{
...
// because images are of fixed resolution 128x128
// I will calculate the scale factor as per the device screen
// so for each device width and height will vary..
// GameUnits is giving scaled width and height need for device
x = get new x;
y = get new y;
width = GameUnits.getWidth();
height = GameUnits.getHeight();
// similarly updating 4 more width & height, each of them are different.
...
...
}
render()
{
...
spriteBatch.begin();
spriteBatch.draw(spriteAnimation.getKeyFrame(totalTime),x,y,width1,height1);
// similarly rendering total of 5 animation
spriteBatch.draw(spriteAnimation2.getKeyFrame(totalTime),x,y,width2,height2);
...
spriteBatch.end();
...
}