Draw over image with background...?
BlitzMax Forums/BlitzMax Beginners Area/Draw over image with background...?
| ||
Would I be able to take a circular chunk out of a square image.. E.g. Square bit of cheese Mouse takes circular bite out of cheese Now if I grab a square of the background image and mask it with a circular image I should be able to draw a chunk of the background over the cheese, making it look like a bite was taken out of it? |
| ||
I would suggest to lock the image with LockImage() to get a TPixMap. Now you can manipulte the picture. E.g. change the Pixels of the "eaten" parts to transparent (Color=0) WritePixel(). At the end you unlock the picture with UnlockImage(). In the next drawing the transparent part of the image will show the background. Graphics 640,480,0,60 ' example needs any picture (>50x50 pix) Image:TImage=LoadImage("..... PixMapImage:TPixmap=LockImage(Image) For Rad%=0 To 180 Local Sinus#,Cosin# Sinus=Sin(Rad)*10 Cosin=Cos(Rad)*10 For X%=0 To sinus WritePixel(PixMapImage, X, 20+Cosin, 0) Next Next UnlockImage(Image) Setcolor 255,0,0 DrawRect 0,0,640,480 Setcolor 255,255,255 DrawImage Image,10,10 Flip WaitKey |
| ||
The plan was not to alter the image of the cheese just to draw over it in the shape of a bite with the background pattern aligned. I can grasp how this would be done in theory with a polygon shaped bite and the background texture applied or a mask/stenciled image? |
| ||
At the root of your question is basically "terrain deformation". But since Bmax still doesn't have "reliable" render to texture for both dx and ogl, you're left with doing things a bit harder. Rather then re-inventing the wheel, there's a good discussion with ideas, tips, etc, here: http://www.blitzbasic.com/Community/posts.php?topic=82438#929874 |
| ||
What should be the sense of drawing again something on front of a cheese, what is already behind the cheese? e.g if the cheese moves, you will have to do a lot of painting in your method. While the transparent way still works without doing anything. What would be the disadvantage of my way in your game? Perhaps I did not understand the traget you follow... |
| ||
What if there are multiple 'cheeses' and they regrow over time? |
| ||
use multiple images i made simple demo: This is almost same as Midimaster's code, but here i just reset pixels alpha value, so when you need to show pixel again. just set pixel alpha to 255. |
| ||
I had an idea for deformable terrain tonight so I knocked this together. It could easily be modified to handle textures. In that code I only subtract but addition would be easy too. The tricky bit would be if you needed to handle rotation. |