开发者

Rotating HTML5 canvas slow?

开发者 https://www.devze.com 2023-04-12 07:54 出处:网络
I\'m experimenting using rotation on canvas, I have it now so each object has its own rotation. Without them rotating I can get around 400 objects on screen on a very low end computer and nearly 2000

I'm experimenting using rotation on canvas, I have it now so each object has its own rotation. Without them rotating I can get around 400 objects on screen on a very low end computer and nearly 2000 on a normally stocked pc. when I factor in rotation more than 0, the performance drops at least a third!

Why is just changing the rotation slowing it down so much? Is this one of canvases weird hiccups?

I have a global rotation variable and at the beginning of d开发者_运维技巧rawing each object I:

ctx.rotate(globRot);


For individual objects cache the rotations. Some of my findings.

Realtime rotation demo

Cached rotations demo (note move up using arrows to find the zombies)


I guess a lot of time might be spent actually creating and multiplying the matrix for the transformation. If you can (find a way to) cache the transformation when it's not changing, that might help. Maybe.

0

精彩评论

暂无评论...
验证码 换一张
取 消