Monday, March 28, 2011

Canvas performance

Hey,

I tried some tests with the canvas objekt. I create a canvas an redraw
the canvas every ms, so I get the FPS for the drawing....

If i use the drawImage method of the Context2d the performance is very
bad. I draw currently about 160 images on a canvas 1920x1200....
But I only get 50-60 FPS...

So is the performance really so bad or do I a failure?

Regards,

Markus

Here the code:

protected final Timer mUpdater = new Timer() {
@Override
public void run() {

double start = Duration.currentTimeMillis();

/*
* Zeichen start...
*/

mContext.clearRect(0, 0, mInnerWidth, mInnerHeight);
mContext.setFillStyle(mDefaultTextColor);

int startW = 0;
int startH = 0;

while(startH < mInnerHeight) {

startW = 0;

while(startW < mInnerWidth) {
mContext.drawImage(ResourceHandler.BUILD_SAEGE_01, startW,
startH);
startW+=ResourceHandler.BUILD_SAEGE_01.getWidth();
}

startH+=ResourceHandler.BUILD_SAEGE_01.getHeight();
}

/*
* Zeichnen ende...
*/

double t = Duration.currentTimeMillis() - start;
double fps = 1000 / (t == 0 ? 1 : t);
mContext.fillText("FPS: " + fps, mWidth - (mWidth * 0.2), 10);

}
};


Example URL: http://thandarocom.appspot.com/game.html

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment