In a Windows Phone 7 Silverlight app I have to manipulate square objects inside a matrix. The only operation I have to do on them is changing their fill color, but I have to do it in a rapid continuous loop, so it must be efficient.
Obviously this requirement is more XNA-like than Silverlight, but I have weighed pro/cons and decided for Silverlight as there are other things that will be way easier in SL rather than in XNA.
The obvious way to do this is to create a Grid and programmatically populate it with Rectangle objects (so that I can keep a reference to each Rectangle in a 2-dimensional array). This works fine in Windows/Web Silverlight, but I'm worried that iterating over the whole Rectangle array while changing their colors may be too slow on the phone (for ex. I don't need all the features of a DependencyObject, but Rectangle 开发者_JAVA百科seems the most basic object with a background color).
Is there a better approach than Grid+Rectangles?
Hard to say without seeing the app, but as opposed to setting up a foreach loop (or whatever) I would create an object of some type (e.g GameBoard), and Bind() the color of each square to a property of GameBoard. Then make some kind of function in GameBoard (e.g. SetSquareColors) with parameters to pass in all the squares at once.
GameBoard.SetSquareColor(x1y1,x2y1,x3y1,x1y2,x2y2,x2y3,x1y3,...)
Or something along those lines...
精彩评论