Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am on to make a table game, I successfully figured out how to make the arrow and to move the cursor on it (by tiles). Now I wanna find out how to make that if I hit the Enter key the tile's texture change to another. I tried like this:

if (input.KeyPressed(Keys.Enter))
    cell[X,Y].Cell_texture = tile_texture;

but it doesn't really work.

share|improve this question
it would be more interesting if you show your draw method... – Blau Apr 15 '12 at 22:01
If you are writing the texture per se in your Draw method, just draw the new one. If you don't care about the old texture (only used in this particular tile) use Texture2D.SetData(...). Otherwise, we need more info. – Elideb Apr 15 '12 at 23:33
Maybe you should change states, not textures per see. And then draw the texture relative to that state. – Gustavo Maciel Apr 16 '12 at 1:33
If you have the asset name of the tile you want, you could just change Cell_texture using Content.Load<Texture2D>('assetName') – Mike C Apr 16 '12 at 3:04
the cell class's draw method: public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(Cella_texture, Cella_position, Color.White); } – Adorjan Apr 16 '12 at 7:53
up vote 1 down vote accepted

In your cell class change Cell_texture to a byte

Add 2 variables

public static Texture2D Texture1;
Tpublic staticexture2D Texture2;

And your switching logic

 if (Keyboard.GetState().IsKeyDown(Keys.Enter))
      cell[X,Y].Cell_texture = 1;

And in your draw method

if (cell[X,Y].Cell_texture == 0)
else (cell[X,Y].Cell_texture == 1)

This will allow you to have multiple cell types, and have a global Texture2D for better memory usage.

share|improve this answer
Also, Seeing your draw method could allow me to give better advice. – Cyral May 7 '13 at 1:13

try this:

Texture2D tile1;

Texture2D tile2;

 if (Keyboard.GetState().IsKeyDown(Keys.Enter))
    tile1 = tile2;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.