Pixel based collision?

Hi,

Is there some way to find out what sprite is visible from a coordinate, i.e. the mouse cursor? I mean, like I click in the game window and want to know what sprite I clicked, but not by "bounding box", but by pixel, so that alpha pixels are not regarded as the sprite ...
I hope you know what I mean and can help me =)

Thanks in advance
Björn

There is no way built into

There is no way built into AgateLib to do this, you have to do it manually. You need to read the pixels from the sprite frames and do your own tests. You can access the sprite frame surface data with mySprite.CurrentFrame.Surface.ReadPixels() or mySprite.Frames[0].Surface.ReadPixels() (replace 0 with a frame index)

There are a couple of issues which complicate things:
1) Every call to ReadPixels locks the surface data and transfers it from video memory to managed memory, so doing this every frame would be very bad performance-wise. So you should cache these for each frame.

2) The Sprite class trims transparent pixels from around the outside of each frame in an attempt to reduce video memory usage (which I have doubts as to how much reduction is actually accomplished). But in order to correctly match the pixels read from the frame surface, you need to either turn off the trimming, or read the FrameOffset property of the sprite frame. Unfortunately, there is no public way to do this; you need to modify the source code in SpriteFrame.cs and recompile AgateLib.

The easiest way would be to turn off the trimming, by commenting out the last two lines of the Private_SetFrame(Surface srcSurface, Rectangle rect, bool trim) subroutine.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.