我正在玩jQuery2d对象绘制到surfaceview,但我不是很满意我得到的帧率(10-13,当有多个对象在屏幕上/在调试更多我得到26-30)。从SurfaceView获得更多的FPS,我可以做些更好的事情吗?
while (isRun)
{
Canvas canvas = holder.lockCanvas();
_update(canvas); /// <- call to update
holder.unlockCanvasAndPost(canvas);
}
...
canvas.drawColor(0xFF6699FF);
for (Body b = world.getBodyList(); b!=null; b = b.getNext()) // <- cycle through all the world bodies
{
rlBodyImage bi = new rlBodyImage();
bi = (rlBodyImage) b.getUserData();
float x = b.getPosition().x*scale + wOffset + camera_x + camera_x_temp;
float y = b.getPosition().y*-scale + hOffset + camera_y + camera_y_temp;
canvas.save();
canvas.translate(x - (bi.getImage().getWidth()*bi.getCoof()*scale)/2 , y - (bi.getImage().getHeight()*bi.getCoof()*scale)/2);
canvas.scale(bi.getCoof()*scale , bi.getCoof()*scale);
canvas.rotate((float) -(b.getAngle() * (180/Math.PI)) , bi.getImage().getWidth() /2 , bi.getImage().getHeight() /2);
canvas.drawPicture(bi.getImage()); // <- draw the image assossiated with current body on canvas
canvas.restore(); // images are stroed as "Pictures" , extracted from SVGs.
}
有没有办法来加快速度,其他那么当然使用更加简单SVGs? :) 谢谢!
编辑:
是的,则要切换到PNG图像,他们让路更好的FPS率。
矢量图片= 10 ... 13 ... 16 FPS
PNG仅= 35 ... 40 + FPS
PNG具有缩放= 32 ... 37+ FPS
PNG与缩放&旋转= 27+ FPS
感谢您的回答,当我必须旋转和缩放PNG时(用户放大或缩小时),PNG的问题才会开始......另一方面,旋转可以通过将SVG的所有可能的旋转角度一个大精灵......但是缩放... –
>>>你应该创建一个包含所有图像的大精灵/图像集<<<你认为这可能是圆顶与图片(从SVG获得)以及?或者只有当我决定换用PNG时才应该进入它? –
我有2.3的Nexus S,所以希望它不是太旧。它在调试中提供了20多个,平均为26-30。 22那时事情变得非常复杂。 :)你认为在JBox2d上改进使用JNI/Box2d有多好? –