on Aug 7th, 2017, 5:55pm, michael wrote:
|This was a question posted by Cliveb on BBC4W forum: Any ideas Richard? |
That's quite a tricky one. The only method I can immediately think of is to create a 2-dimensional byte array that contains a copy of the sprite's transparency mask. Then if you detect that the click is within the 'sprite rectangle' - by comparing coordinates - you can then check the array to see whether it's on a 'transparent' or 'opaque' pixel.
In pseudo-code terms it would be something like this:
IF clickX >= spriteX IF clickX < spriteX+spriteW IF clickY >= spriteY IF clickY < spriteY+spriteH IF mask&(clickX-spriteX, clickY-spriteY) THEN
REM Clicked on opaque region of sprite
Note the use of cascaded IFs rather than AND. This short-circuit evaluation is faster and avoids the 'subscript out of range' errors that you would otherwise get by accessing the mask array when the click is outside the sprite.
I hope this is helpful.