Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
1  
it would be more interesting if you show your draw method... –  Blau Apr 15 '12 at 22:01
1  
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
1  
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
add comment

2 Answers

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)
    //DRAW TEXTURE1
else (cell[X,Y].Cell_texture == 1)
    //DRAW TEXTURE2

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
add comment

try this:

Varibles:
Texture2D tile1;

Texture2D tile2;

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

Your Answer

 
discard

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.