pixmap selection with mouse
BlitzMax Forums/BlitzMax Programming/pixmap selection with mouse
| ||
Suppose you have x pixmaps on screen of arbitrary shape (not rectangle or polygon constrained) What should I do to detect which pixmap touches the pointers hotspot? I mention the arbitrary shape because the image may be a circle so I would like to have pixel accurate detection Thanks everyone William |
| ||
you can first find out if the mouse pointer is inside the pixmap canvas. then check out if the pixel that the pointer is on is transparent or not. if not store the pixel. |
| ||
Could you please give me te command to check for canvas and the command to check the pixel pointer? just the name so that I can a have a start Thanks for the response William |
| ||
For the Canvas it's simple. Let's say that your pixmap it's at the position x , y If x - MouseX() < PixmapWidth(yourPixmap) And y - MouseY() < PixmapHeight(yourPixmap) drawtext("in canvas") end if For the other stuff have a look in the wiki. http://www.blitzwiki.org/index.php/ReadPixel Tell me if it works I never done something like this. Good Luck |
| ||
You know your pixmaps x/y position and it's width/height. Check whether mousex() and mousey() is within this rect. Get the offset if mousex()/mousey() into the pixmap rect. Check the colour of the pixel at this point. If it's non-transparent... collision. Strict Graphics 800,600,0 Local pixmap1:TPixmap=LoadPixmap("max.png") Local pixx:Int=200 Local pixy:Int=200 While Not KeyHit(key_escape) Cls Local mx:Int=MouseX() Local my:Int=MouseY() DrawPixmap pixmap1,200,200 If mx>pixx And mx<pixx+PixmapWidth(pixmap1) And my>pixy And my < pixy+PixmapHeight(pixmap1) Local mypixel:Int=ReadPixel(pixmap1,mx-pixx,my-pixy) If mypixel<>0 DrawText "COLLISION",0,0 EndIf Flip Wend The image I used here has transparent (0) background, You'll need to get an argb value from your mask to check for values. |
| ||
This works great as long as you have on this specific rectange a pixmap, what happens if you have two overlapped pixmaps where at some areas pixels of one pixmap are hidden (within the same pixmap rectange) and on another part pixels of the other pixmap are hidden? Suppose you have 2 pixmaps, one is the an image of the letter A and the other an image of the letter B but their canvases are exactly the one on top of the other. Even so some pixels of one letter are visible while at onother spot pixels of the other letter are visible. How can I distinguish which letter the pointer is 'touching'? Thanks |
| ||
It doesn't mater even if you don't draw your pixmap it's just checks the x y coordinates that suposed to be draw. |
| ||
Create a mypixmap type with fields x,y and name then stick them on a list. Do the mx/my check against the list and return each pixmap collided (possibly in an array). Check the collideimage code as it does something similar. If you only want 1 pixmap returned then draw them with Z-order and return the highest if there's more than 1 collision. |
| ||
Thanks everyone for their replies!!! |
| ||
Just use a loop |