Followers 0

# XNA questions

## 10 posts in this topic

I have a few simple questions that don't require much thought, so I figured I'd put them in one thread instead of making a bunch of threads. I don't know where else to put them lol.

1: If I have one million cubes, is it faster to draw them from one big list, or 20 smaller lists?

2: When I'm drawing a skybox, should I have it drawn relative to the player or to the map?

3: Is there a method that can change how a texture looks depending on player color? For example, if player ones color is red, part of the texture will be red. I don't remember what the exact word for it is...maybe alpha blending or something like that.

4: In a multiplayer game, I'm assuming it's correct to create a camera for each player. Is this easiest to do through the player class?

5: What's the difference between the LoadContent and Initialize method created for you? I use both of them while initializing variables, although I'm not really sure why

0

##### Share on other sites

1: If I have one million cubes, is it faster to draw them from one big list, or 20 smaller lists?

Generally the fewer draw calls the better - so, one big list. However, if you can avoid drawing any of your 20 smaller lists (say because you know that none of the cubes in that list will be visible from the current camera), then 20 smaller lists is the better way to go.

3: Is there a method that can change how a texture looks depending on player color? For example, if player ones color is red, part of the texture will be red. I don't remember what the exact word for it is...maybe alpha blending or something like that.

You could use a second texture that indicates which parts of the first texture get replaced by red. Then write a custom shader that uses these two textures to determine the final output color.

Or, draw the object twice. Once normally, and then again using the "team color" texture that is transparent where you want the original color to show through.

1

##### Share on other sites

Your first answer helped a lot. Since the entire map is huge, I'll end up using smaller lists. And fog too.

With the texture I'm using it'll be easy enough to determine which colors to change to the player color. If the pixel is a certain shade of gray and the player places it, that shade of gray will change to the player color

0

##### Share on other sites

1: If I have one million cubes, is it faster to draw them from one big list, or 20 smaller lists?

If that million is ON SCREEN, then it should be faster to draw from one list... if for "list" you mean drawcall.

If they are not all visible, then having the possibility to discard cubes might be faster. There's a sweet spot to be found between batch size and ability to cull out blocks and that is very application specific and can only be found through benchmarking your own game.

0

##### Share on other sites

If I have one million cubes, is it faster to draw them from one big list, or 20 smaller lists?

Neither, your still doing 1,000,000 draw calls wither way. what you need to-do is only draw them if they are onscreen and through the use of Culling or instancing.

Is there a method that can change how a texture looks depending on player color? For example, if player ones color is red, part of the texture will be red. I don't remember what the exact word for it is...maybe alpha blending or something like that.

No, Make one you will need to use RenderTargets to modify the texture. here is a snippet how to use a rendertarget:

RenderTarget2D target = new RenderTarger2D(...);
//I cant remeber the arguments off the top of my head.
//I think its GraphicsDevice, Width, Height, GenerateMipmap, SurfaceFormat, Depthformat

GraphicsDevice.SetRenderTarget(target);
GraphicsDevice.Clear(Color.Black); //any colour will do
using(SpriteBatch b = new SpriteBatch(GraphicsDevice))
{
b.Begin();

//Draw anything here to draw onto a new texture E.g.
//Draw the Basic non-coloured texture
//Draw the players colour where we are supposed too.

b.End();
}

GraphicsDevice.SetRenderTarget(null);

//Then to access your new Texture, just do
Texture newTexture = target; //Target inherits from Texture2D so no casting needed


In a multiplayer game, I'm assuming it's correct to create a camera for each player. Is this easiest to do through the player class?

Depends, Local multiplayer, E.g. on the same PC? s this the design you want? I would probally have 1 camera class (Singleton maybe?) which contained ALL the informatio

What's the difference between the LoadContent and Initialize method created for you? I use both of them while initializing variables, although I'm not really sure why

GraphicsDevice ... Initialize() ... is called just after the constructor, that's it. it is never called again until you create another instance of the class.

Whereas LoadContent<T>() ... is called on starup AND whenever the graphics device is Lost or Reset recovering your ingame assets.

This means that LoadContent is called when the Game Window is minimized and reopened, or something takes control of the screen (E.g. UAC) and everything run in loaded is run again, this means it is not a good idea to put any data initialization in here, as it will be "reset" when your device is reset / lost.

Edited by Andy474
2

##### Share on other sites

Thanks! I guess when the time comes I'll have to figure out a way to get a certain RGB value of a texture and then change it according to player color. When I was playing around with sprites I recalled that pink was always transparent, so I figured I could take a color and make it transparent, then draw over it with the player color

0

##### Share on other sites

GraphicsDevice ... Initialize() ... is called just after the constructor, that's it. it is never called again until you create another instance of the class.

Whereas LoadContent() ... is called on starup AND whenever the graphics device is Lost or Reset recovering your ingame assets.

This means that LoadContent is called when the Game Window is minimized and reopened, or something takes control of the screen (E.g. UAC) and everything run in loaded is run again, this means it is not a good idea to put any data initialization in here, as it will be "reset" when your device is reset / lost.

That may have been true in older versions of XNA, but not anymore. LoadContent should only be called once.

0

##### Share on other sites

That may have been true in older versions of XNA, but not anymore. LoadContent should only be called once.

Not what MSDN Says:

This method is called by Initialize. Also, it is called any time the game content needs to be reloaded, such as when the DeviceReset event occurs. You should not access the GraphicsDevice until LoadContent is called.

LoadContent is called by Initialize, and before Draw. During the time the code for this method is executing, the user will experience a delay before the initial game screen appears.

Edited by Andy474
0

##### Share on other sites

As is often the case, MSDN is wrong (see here: http://xboxforums.create.msdn.com/forums/p/27316/150367.aspx#150367). It's pretty easy to verify this yourself by adding a DeviceReset handler, and putting a bp on it and on your game's LoadContent.

XNA will recreate most graphics resources automatically. The only resources that "lose" their data on a device reset are render targets, DynamicVertexBuffers, DynamicIndexBuffers and maybe I few more I can't remember.

Edited by phil_t
0

##### Share on other sites

As is often the case, MSDN is wrong (see here: http://xboxforums.create.msdn.com/forums/p/27316/150367.aspx#150367). It's pretty easy to verify this yourself by adding a DeviceReset handler, and putting a bp on it and on your game's LoadContent.

XNA will recreate most graphics resources automatically. The only resources that "lose" their data on a device reset are render targets, DynamicVertexBuffers, DynamicIndexBuffers and maybe I few more I can't remember.

Interesting ... I'll take the word on it, but if i remember correctly a game i made a while ago used to have problem that every time the game was Minimized all the content would reload and score rest etc. (this was in XNA 3.0) and i got around this by moving all Data stuff (scores etc. out of the LoadContent method. )

So

Edited by Andy474
0

##### Share on other sites

2: When I'm drawing a skybox, should I have it drawn relative to the player or to the map?

Skybox should move with the player. But only translation; rotation of the skybox must be fixed with the map.

The reason why you want to move skybox with the player is that this way it will appear to be really far away and you don't need an extremely huge skybox model. If the model wasn't incredibly huge and if it didn't move with the player, it would appear to be very close, which would break the immersion.

Edited by Tom KQT
1

## Create an account

Register a new account