Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Making a texture mask

$
0
0
Hello guys! Totally new here, as well as to graphics programming in general. I'm making a 2D fighting game engine using XNA/MonoGame, and oddly enough what's tripping me up is how I can have the user define their lifebars. Obviously the simplest (old-school) method would be to just use a bounding rect to cut off the display region of the current sprite/animation to only the "remaining life" region. Done. But what if they want to define some other non-rectangular shape for the end of the lifebar, such as a rhombus, or pill shape? So I figure, why not have them make a mask sprite to define what the end of the lifebar should look like? That way they can have whatever end shape they want at any point in the lifebar, whether it's a static sprite or animation. It will also provide another useful tool familiar to designers that they can also use anywhere else in the engine. Basically, I want the user to be able to insert a sprite like this: And a sprite like this: And end up with this at the end of the lifebar (after aligning the mask with the end of the lifebar): The algorithm itself is simple. I just need it to take the sprite and multiply it by the color (or color component, to simplify things) in the overlapping mask sprite. But the problem is this: the mask texture and the lifebar texture may be different dimensions. In what I've worked with in HLSL so far, the texture indices are represented from 0.0F to 1.0F in the X or Y direction. So in my head, that mask sprite is going to be treated the same size as the lifebar texture, which means it would create a totally different image as the life decreases! I'm using HLSL, but I'm unsure how to approach this problem. Is there any way to check image dimensions so I can tell it to use the mask texture as-is, and not clip anything outside of the mask texture?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>