Advertisement

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

Started by June 23, 2017 06:21 AM
1 comment, last by Scouting Ninja 7 years, 7 months ago

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?

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.

This topic is closed to new replies.

Advertisement