Thank you very much. This has cleared up the problem entirely, although I had to use the formula:
image.data[(y+1) * image.pitch + x * 4 + 3] Any idea of why that might be? Format is BGRA. Will this formula change depending on the format? Thanks again, Nate On Jan 22, 6:31 pm, "Alex Holkner" <[EMAIL PROTECTED]> wrote: > On 1/23/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > I'm sorry if this is the wrong place to post this, but this was the > > only place I could find to discuss pyglet programming. I'm currently > > trying to move a 2d game system over to pyglet from pygame. In the > > pygame code, collision is checked for using a bitmap, allowing the > > level to contain arbitrary curves and still react correctly. I am > > trying to replicate this behavior. > > You'll get much better performance by using some OpenGL tricks. For > example, use the selection buffer to check for the intersection > between a rectangle (or point) and an arbitrary image. Use a > combination of the stencil buffer and occlusion query tests to check > for intersection between two arbitrary images. > > > The way I am currently doing it is as follows: I read an image in > > from file. I convert that image to its data. I take a region of the > > data which is one pixel known to be fully transparent. I change the > > format for that region to 'A' (Alpha). Then, whenever I'm checking > > for collision, I take a one pixel region at the x and y coordinates, > > convert the format of that to 'A', and compare the value of its data > > to the value of the sample pixel's data. If they aren't equal, a > > collision has occurred. > > > Converting the format of an ImageData or ImageDataRegion is very > > expensive, though, and slows my program down to a crawl. Is there any > > way to get the Alpha without performing this operation, or is there a > > better way to do this? > > You can use the data in its existing format. i.e., it will probably > be in something standard like 'RGBA'. Then to get the alpha component > at x, y: > > image.data[y * image.pitch + x * 4 + 3] > > Alex. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
