|
  
|
|
|||||||
| Development Discussions All developers who are coding games may stop by here for any help, suggestions, and everything development related. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Zuner
Join Date: May 2008
Posts: 75
Reputation: 53
|
Please help, this is really frustrating me. I'm working on a music component for my game and I want to include album art. If I use this code:
Code:
spriteBatch.Draw(album.GetAlbumArt(game.Services), new Rectangle(somewhere), Color.White); Code:
if (album.HasArt)
{
Texture2D a = album.GetAlbumArt(game.Services);
spriteBatch.Draw(a, new Rectangle(somewhere), Color.White);
a.Dispose();
}
![]() |
|
|
|
|
|
#3 (permalink) |
|
Zuner
Join Date: May 2008
Posts: 75
Reputation: 53
|
So then calling it for every single album at the start of my program is a better option? Won't I just end up with hundreds of textures then? That doesn't sound like it will help the memory problem. Is there another solution?
![]() |
|
|
|
|
|
#4 (permalink) |
|
Jr. Member
Join Date: May 2008
Posts: 410
Reputation: 60
|
No, no, no. Misinformation abound here. GetAlbumArt being "intensive" has nothing to do with it. In fact, that method is really quick at doing what it does. What is relevant is that the texture it returns is not automatically disposed. This means that it doesn't ever unload the texture data without you manually unloading it. You can choose to load it all up front, but that's rather memory wasteful, especially if you only need to show a handful of art at a time.
What you want to do is keep a reference to the texture somewhere. So in whichever class you're wanting the art, put this: Texture2D albumArt; Then whenever you want to get the album art to draw (like when the user changes what is selected or whenever it is that this needs to change), you want to make sure to dispose of the old texture and then call the GetAlbumArt method: if (albumArt != null && !albumArt.IsDisposed) albumArt.Dispose(); albumArt = album.GetAlbumArt(Game.Services); Then feel free to render it all you want. You might also want to safeguard your draw method to make sure the album is valid: if (albumArt != null && !albumArt.IsDisposed) spriteBatch.Draw(albumArt, ....); |
|
|
|
|
|
#5 (permalink) | |
|
Zuner
Join Date: May 2008
Posts: 75
Reputation: 53
|
Quote:
![]() |
|
|
|
|
|
|
#7 (permalink) | |
|
Jr. Member
Join Date: Apr 2008
Posts: 392
Reputation: 121
|
Quote:
|
|
|
|
|
|
|
#9 (permalink) | |
|
Jr. Member
Join Date: Apr 2008
Posts: 392
Reputation: 121
|
Yeah, it's still terrible to use it every frame! The problem wasn't directly related to the question.
Heres a quote to better explain: Quote:
|
|
|
|
|
|
|
#11 (permalink) |
|
Experienced Zuner
Join Date: Nov 2007
Posts: 112
Reputation: 38
|
... that was totally unnecessary, I think a lot of people made that mistake when they first tried using it. It's not immediately obvious that the zune wouldn't already have the album art in memory and would have to go to the harddrive every time. Jeeze, no need to insult the guy.
__________________
-Mark Check out my new game, "Squadron Z": To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. Check out my version of pong with multiplayer: To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. |
|
|
|
![]() |
| Thread Tools | |
|
|
| |