Game Development Community

Checking Mouse Click on a sprite

by Tim Finch · in Torque X 2D · 03/13/2007 (4:29 pm) · 3 replies

The XNA object - TEXTURE2D has a method .GetData(). This is useful for checking if the mouse is clicked on non-alpha section a sprite, and a good example can be seen here:

http://www.ziggyware.com/readarticle.php?article_id=80

However - how would I do this for a torque X T2DStaticSprite? There is no GetData method so is it possible to access pixel data like this?

any help would be much appreciated.
Tim

#1
03/13/2007 (10:17 pm)
Something like the following:

T2DStaticSprite sprite; // assume this points to something
ITextureMaterial mat = sprite.Material;
if (mat)
{
   // if we assume the material has been preloaded, 
   // we could get the Texture resource via: 
   // Resource<Texture> res = mat.Texture;
   // Texture2D bitmap = (Texture2D)res.Instance;

   // lets do it the hard way
   string textureFile = mat.BaseTex;
   Resource<Texture> res = GFXDevice.Instance.TextureManager.LoadTexture(textureFile);
   Texture2D bitmap = (Texture2D)res.Instance;

   // ... bitmap.GetData ...

   // if we called LoadTexture ourself, we need to cleanup the temp resource
   res.Invalidate();
}
#2
03/14/2007 (4:09 pm)
Wow - Thanks so much, just what I needed! I have only just joined this community, having been excited by the idea of XNA and a little frustrated with some of the other Basic orientated gaming languages; and the first thing I noticed was how many posts are by employees of GG, taking time to help and advise even with noob questions like mine, which is really cool. Thanks again.
#3
03/14/2007 (4:29 pm)
Don't let them fool you. GG is a 1 man shop with multiple personalities who outsources forum replies to India not because it's cheaper, but because he misspelled Idaho.

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif