Jump to content
  • Advertisement

This topic is 385 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:

Photoshop_2017-07-01_13-57-52.png.a844ed385663f728b6b519f5366df053.png

 

And a sprite like this:

Photoshop_2017-07-01_13-58-30.png.d57b03398b26f2867a6b4c5070837f57.png

 

And end up with this at the end of the lifebar (after aligning the mask with the end of the lifebar):

Photoshop_2017-07-01_13-59-08.png.7e02f1563356e143e45595eee6b12a72.png

 

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?

Edited by Jesuszilla
DX11 tag since HLSL is for DirectX

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!