I ended up choosing option 3. Basically, I have a Tile class that contains texture and size. Size n means that there are n * n subtiles in this tile. I also have an array that keeps track of which tiles are destroyed or not. My class looks like this in pseudo code:
class Tile texture dimention int [,] subtiles; //0 or 1 for each subtile public Tile() // constructor subtiles = new int[dimention, dimention]; intialize_subtiles_to(1); public Draw() // this is how we know which one to draw //iterate over subtiles for(int i.. for(int j ...) if(subtiles[i,j] == 1) Vector2 draw_pos = Vector2(i*tilewidth, j*tileheight) spritebatch.Draw(texture, draw_pos)
Similarly, I have a collision method that will check for a collision:
public bool collides(Rectangle rect) //iterate over subtiles for i... for j.. if(subtiles[i,j]==0) continue; subtile_rect = //figure out the rect for this subtile if(subtile_rect.intersects(rect)) return true; return false;
And so on. You can imagine how to โdestroyโ certain substructures by setting their corresponding value to 0 and how to check if the entire fragment is destroyed. Provided by this technique, all litter will have the same texture. So far I canโt come up with a simpler solution.
source share