- Home /
2D plane not drawing texture correctly
Hi,
I'm new to Unity and trying to make a 2D game for iPhone. I'm using Sprite Manager 2 and have the camera set to orthographic with an orthographic size of 160 (for 480x320 landscape resolution).
I have a sprite that is 480x68 in size. I have applied the standard Sprite script from SM2 to the game object. When I play test the game, the camera looks right and the sprite looks correctly positioned, but the texture is slightly wrong. It has cut off a bit from the right side of the texture and stretched it. It also appears to be tiling slightly on the Y axis.
Screenshot of what the sprite looks like along with the settings I configured:
Here is what the image should look like:
How do I get the texture to appear correctly?
EDIT: Just noticed that you can't make out the settings, here they are: Width: 480 Height: 68 Lower Left Pixel: X: 0 Y: 67 Pixel Dimensions: X: 480 Y: 68
I managed to fix this by changing the following values: Lower Left Pixel: X: 0 Y: 57 Pixel Dimensions: X: 500 Y: 58 However I would like to understand why this has fixed it, and find an algorithm for deter$$anonymous$$ing these values, rather than guessing them until it looks right.
Answer by disband85 · Dec 09, 2010 at 02:46 AM
Yes, the texture is being wrapped around if it's too small for the size of the sprite. The problem is trying to find the right, exact size (pixel dimensions) for the texture to fit the sprite. After doing many sprites now, there seems to be no method for figuring this out apart from guessing. Basically I make the pixel dimensions the same size as width and height initially, then run in game and keep changing pixel dimensions until the texture fits properly. It seems to be completely random as to how much you need to change it (doesn't correlate to image size of your texture at all).
One thing I did notice is that most of the time, the lower left pixel Y should be the same as pixel dimensions Y. Changing the lower left pixel X and Y offsets the texture by the respective axis.
Answer by The_r0nin · Dec 06, 2010 at 05:51 AM
It appears that the top of your sprite is being wrapped-around to the bottom of your image. This could be a UV problem (where the UV's of your object are out of alignment) or a case where the sprite is not being aligned like you think is should. I don't know much about Sprite Manager 2, but perhaps the texture has been compressed? A power-of-2 texture size height might give you better results (but, then again, 58 isn't a power of two...)
thanks for your suggestion. You're right in that the texture wraps around. I don't think the UV alignment is wrong, more like the wrong size (eg. 0 - 0.7 ins$$anonymous$$d of 0 - 1). $$anonymous$$aking the pixel dimensions powers of 2 didn't help.
Your answer
Follow this Question
Related Questions
Creating a 2D game using planes with textures 1 Answer
2d game for iphone, use pixel perfect or not? 0 Answers
2D car track method 1 Answer
2d Sprite Sheet on characters ruined in unity 1 Answer
iphone 2D settings 2 Answers