Monday, March 23, 2009 10:07 AM
I have a Viewport canvas that is, say, 700x500 pixels.
I have a GameSurface canvas that is say 15,000 x 5000 pixels.
The GameSurface is a child of the Viewport and the Viewport clips the GameSurface so only a portion of the GameSurface is visible at any given time.
The GameSurface has both static UIElements (Landscape geometry) and Dynamic UIElements (Player character).
As the Player character moves around on the GameSurface (by applying RenderTransforms to the player), the GameSurface itself is moved with respect to the Viewport (by applying RenderTransforms to the GameSurface) to keep the Player character centered within the viewport.
This is essentially a viewport/camera system I have set up.
My question is this:
How should I set up BimapCaching on each of my game elements (see list below) to take best advantage of GPU acceleration.
Static Children of GameSurface
Dynamic children of GameSurface
A pointer to any info related to this is also very welcome.
Monday, March 23, 2009 10:45 AM
Holy smokes, what a great question. I'm using the same setup and I'm about to break out the SL3 bits, so I hope you get a solid answer on this soon.
Two questions for you in the meantime, Jeff, if you don't mind:
- I'm assuming your Player control is a child of GameSurface. Did you find that RenderTransforms were vastly more performant than plain 'ole Canvas.SetValues on Top/Left? Any difference?
- Sounds like you've implemented pixel-by-pixel scrolling (as opposed to "pages" at a time). I started with your approach but low-end laptops just couldn't handle it so I went w/ pages. I'm assuming this won't be an issue with SL3, but I'm curious if you got smooth scrolling to work well on lower-end systems with SL2. If so, would be great to compare notes.
Monday, March 23, 2009 12:59 PM
I would bitmap cache the Landscape geometry.
It won't help to apply bitmap caching to the entire GameSurface or ViewPort because you have dynamic elements in there.
One thing to beware though - if any of your Landscape geometry is big (over about 2048 pixels in width or height), you will want to break it up into "tiles" of some sort. Because on some older video cards, the hardware surface will be too large and it won't get cached.
Hope this helps!
Monday, March 23, 2009 1:29 PMOk, so I should bitmap cache the landscape (keeping it chunked up into bite size pieces). Sounds good. What about the dynamic objects. These would be children of the GameSurface that I move around using RenderTransforms. Should I cache these as well? What about just bitmap caching all children of the GameSurface since these will all be "game" objects. (no old school UI controls etc..) Asked another way is there any reason I wouldn't want to bitmap cache something on my GameSurface? (assuming all objects are not too large?) -Jeff
Monday, March 23, 2009 1:35 PM@Frefln, I'm not sure if RenderTransform is faster or not. It just like using it more than the whole left, top thing. It allows me to combine rotations, translations, and scale all into a single entity. Not sure what exactly you mean by pixel-by-pixel scrolling. My character moves around according to the physics engine and I move my GameSurface accordingly. I only use vector graphics (no bitmaps images). I'm building a side scrolling game so I couldn't really scroll by "page"
Monday, March 23, 2009 1:49 PM
When you say dynamic objects, do you mean the player and other sprites? If they change much, and I think they will, you won't see much improvement with bitmap caching. For example, say you have a Canvas that contains the arms, legs, and body of a player sprite and those get animated independenty inside the Canvas. That would be a bad candidate for Bitmap Caching.
However, let's say you have a Canvas that contains a bitmap of a Snowball (I think I know what game you're working on here ) and it doesn't contain any animated pieces... And it has a Rotate Transform which makes it Roll around on the ground. That _would_ be a good candidate for Bitmap Caching because Transforms are supported in the Bitmap Cache.
Hope that makes sense?
I want to try and pull together some more stats using the "Monkey Scroller" sample from this post, so we can all have some concrete examples of the performance... Just have a couple of other priorities as usual.
Monday, March 23, 2009 3:47 PMOk, I think I get it. My "character" actually has 7 individual canvas objects all connected by joints. NONE of them use storyboard animations of any kind. All animations are physics driven. They are all positioned within the GameSurface canvas via translation and rotation transforms. So, I think this makes them good candidates for caching. And yes, you are correct which game I'm working on... however, there may or may not be snow involved. :-) Some stats and best practices would be nice. I'll post any interesting results I run across once I start testing the GPU stuff in my game. -Jeff
Monday, March 23, 2009 4:00 PM
Yep, so you could bitmap cache each little body part on the dude. But I'm betting the biggest performance improvement will be when you cache those big landscapes scrolling by.