Sprite Control Lib
Blitz3D Forums/Blitz3D Programming/Sprite Control Lib
| ||
| Hi, I was using the sprite control lib in the code archives... however, I am wondering how one would go about implementing collisions and mouse selects with that library? I have tried to add this into the code:
; create a blank sprite image (from a quad mesh)
Function CreateImage3D(w=1,h=1,par=-1)
If par=-1 par=spritecam
Local sprite=CreateMesh(par)
Local s=CreateSurface(sprite)
AddVertex s,-1,1,0 ,0,0 : AddVertex s,1,1,0 , 1,0
AddVertex s,-1,-1,0 ,0,1 : AddVertex s,1,-1,0 , 1,1
AddTriangle s,0,1,2 : AddTriangle s,3,2,1
;Here is what I added to try and get picking working
EntityPickMode sprite,1
EntityRadius sprite,w
EntityFX sprite,1+16
ResizeImage3D sprite,w,h
Return sprite
End Function
You can see the rest of this cool library in the codr archives. |
| ||
create a button type:type button field entity,name$ field x,y,w,h end type function createButton(name$,x,y,image$) b.bnutton=new button b\name=name b\entity=loadimage3d(image) b\x=x : b\y=y b\w=imagewidth3d(b\entity) b\h=imageheight3d(b\entity) end function then treat as a normal button as you would in 2d.
mx=mousex()
my=mousey()
if mousehit(1)
for t.button=each button
if mx > t\x and mx < t\x+t\w
if my > t\y and my < t\y+t\h
; you've selected a button
return t\name
endif
endif
next
endif
|
| ||
| Not a bad idea, although you loose out on the pixel perfect collision offered by the 2D collision functios. Still it's much better than what I came up with ;) Any idea if writing the sprite to the backbuffer, then using a copy rect to make an image for the overlap thing would be too slow? |
| ||
| Assuming you're using alpha channeled images you can use crude rectangle-based intersections to do your first order collision detection and then double check by looking up the pixels on the alpha channel portion of the texture. |
| ||
| Very good idea! I like that a lot. *** Stupid newb question warning *** What is the bit comparison I need to make to get the alpha channel on a readpixel? |
| ||
| I call upon the creator of SpriteControl to add SetBuffer3D, LockBuffer3D, Read/WritePixel3D (including alpha channel) ... |
| ||
| Well, I see that's not where the problem is (last post) but now I have another (or a request): How to modify drawimage3d to allow specifiying frameX,frameY individually. Now it has only one frame parameter... |
| ||
| The ImagesOverlap3D() function should help. Use the overlap1 and overlap2 parameters to allow the sprites to overlap by x amount of pixels before a collision is triggered. I have not updated SpriteControl for a fair while and it's unlikely to be updated in the future. |
| ||
| By last post I meant my stupid question about SetBuffer3D/Lock/writepixels since I missunderstood - one can just manipulate the texture. The collisions was some other folks questions. My question: DrawImage3D uses one 'frame' parameter but spritecontrol clearly uses frames along both axes, although I don't understand exactly *how* it does it - so that's why I want help modifying DrawImage3D to take x-frame and y-frame parameters... |