Jump to content
  • Advertisement
Sign in to follow this  
Scouting Ninja

Merge a small sprite over a large sprite at it's center?

This topic is 538 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

So I am using Unity, I have a large sprite and a small sprite that I am merging with SetPixel, in code c#.

This was working fine while both sprites was the same size as I would just multiply the two pixels. Now when I try it I get an error because it doesn't fill the array, so I filled in with a blank vector, it works, except now the sprite is in the upper left corner.

What is the math for merging any larger sprite with a smaller one at it's center?

Edited by Scouting Ninja

Share this post


Link to post
Share on other sites
Advertisement

So I found a fix: just move the X by (sprite.width- sprite2.width) /2 and move the Y by (sprite.height- sprite2.height)/2.

Then you need two branches to prevent the getPixel from reading sprites that isn't there.

 

I would still appreciate a cleaner solution because this uses a while loop to adjust the pixels and is slow. Where my other one uses the rectangle of the sprite from the texture and isn't even noticed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!