So hi, I have a problem. I want to show an object (Texture2D) in an area tapped by user. This is my fields :
List<Texture2D> list = new List<Texture2D>();
List<Vector2> list2 = new List<Vector2>();
List<int> list3 = new List<int>();
list, is used to store the object. list2, used to store tapped coordinate. and list3, is used to store object timeout (after 100ms, the shown object vanishes)
This is my update method
protected override void Update(GameTime gameTime)
{
TouchCollection touchState = TouchPanel.GetState();
foreach (TouchLocation t in touchState)
{
if (t.State == TouchLocationState.Pressed)
{
list.Add(Content.Load<Texture2D>("base_grass"));
list2.Add(new Vector2 { X = t.Position.X, Y = t.Position.Y });
list3.Add(100);
System.Console.WriteLine("added : " + t.Position.Y + "," + t.Position.X);
}
}
for (int i = 0; i < list3.Count; i++)
{
list3[i]--;
if (list3[i] <= 0)
{
list.RemoveAt(i);
list2.RemoveAt(i);
list3.RemoveAt(i);
}
}
base.Update(gameTime);
}
(base_grass is the name of my object. It is a plain rectangle image)
The "for" statement is to remove the object when the time expires.
And this is my draw method
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
_spriteBatch2.Begin();
for (int i = 0; i < list.Count; i++)
{
_spriteBatch2.Draw(list[i], list2[i], new Rectangle(0, 0, 64, 64),
Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 1);
}
_spriteBatch2.End();
base.Draw(gameTime);
}
Nothing shown when I clicked on the screen.
But if I change the _spriteBatch2.Draw into this
_spriteBatch2.Draw(list[i], new Vector2((64 * 0),(64 * i)), new Rectangle(0, 0, 64,64), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 1);
It worked, but shown vertically, not on the tapped / clicked coordinate.
Anyone know where my problem is? Thanks