ImagesCollide2 and DrawSubImageRect Images?
BlitzMax Forums/BlitzMax Programming/ImagesCollide2 and DrawSubImageRect Images?
| ||
Hi All, I'm using image atlases by using DrawSubImageRect, but I've just tried to use ImagesCollide2 on them and of course it doesnt work on how I want it to work :) Any ideas on a solution to use ImageCollide2 and image atlases? Cheers, Steve |
| ||
either write your own check... pixel based should be similary fast/alow... or hold a timage of each sprite in the memory. of course the first option geta trickier if you allow rotation and scaling. Bye Ron |
| ||
To expand on the 'your own check' idea, if you look at the source of Max2D.bmx the pixel-collision code uses a quad that represents an image. I think it's possible to make another function that creates that same quad object out of a subsection of the image, then proceed to use that quad normally to check collisions with the built-in code. So you would be testing collision with the same sub-rectangle that you are drawing with your atlases. You should be able to do that by modifying copies of the functions ImagesCollide2, CollideImage and CreateQuads. The latter is the one where you would create a TQuad to represent a subsection of the image, but it might be more complicated than that. The other functions of the collision system that were not mentioned above shouldn't need changes. https://github.com/blitz-research/blitzmax/blob/master/mod/brl.mod/max2d.mod/max2d.bmx#L1160 |
| ||
Thanks guys, I'll have a look at altering max2d :) |
| ||
Hmm, I am not sure you will even need to alter max2d. If you make your own copy of code in max2d.bmx[1483] Function CreateQuad:TQuad(image:TImage,frame,x#,y#,w#,h#,id:Object) and add a pixmap argument, which if not null you could use instead of the images pixmap to set the quads mask member Then you could keep a pixmapwindow object with your sub rectangle shapes that represents the cell on the atlas and pass that in (it would be better not to create one each time). |
| ||
Of course, even simpler would be to switch to using plain DrawImage of cells created with LoadImage(pixmapwindow) for your atlas stuff, it is simpler and just as optimal as DrawImageRect. Hmppf... that is indeed a smart approach ... ... and I am still using the rect-variant based on the idea to save texture switches to improve performance. While pixmapwindow-variant is "virtual", LoadImage() is not using the reference but creating a kind of pixmap-copy / texture. (when manipulating the original image, the "window"-referencing-image is not updated) If LoadImage would work with references, the following example should show similar "image portions" after hitting "space". bye Ron |
| ||
Oops, my bad. I know better now thanks Ron. |
| ||
I would lke to get your approach working as it would allow things like tileimage for referenced image portions ...for now you can only use loops and draw it x/y times. Would save me some code in my sprite-type. PS: my post above wasn't meant offending. Bye Ron |