The other day I were reading some great articles about creating a game step-by-step by Joel Neubeck. I looked at the source code and saw that he were placing his sprites different then what I have seen before. I wrote a comment to Joel on his blog. You can read it here.
Untill now I have only seen samples, and have also only done it this way myself, of placing sprites using a Canvas and the attached properties Canvas.Left and Canvas.Top. This have worked fine for others and for me.
By looking at Joels source code I saw that he were using a Grid as his container to hold his sprites and the a TranslateTransform to place them on the Grid.
Well, I know, the outcome is the same, but it made me think if there actually were a performance difference. So I desided to do a little test my self. I build two small Silverlight applications, both with the same content - balls bouncing around. One is using a Grid as the container and the other a Canvas.
You can see the samples live here:
Canvas sample
Grid sample
You can download the source code from here.
To me they look exactly the same. As you can see, if you run Firefox, that I have enabled the FrameRateCounter and have set the mas framerate to 9999. On my computer these are pretty much the same all the time. In Chrome I can see the memory useage of the silverlight plugin and that seems to be the same as well.
- So, are they actually performing the same or am I testing this the wrong way?
- Do you have any better way of testing this?
- Does it perform differently on your computer?
Please let me know, as I think this is very good to know for all us game developers :)