- Home /
GUI.Rect() 1 pixel offset? [JS]
Hello, I am having a very odd error where I am drawing a Rect and it appears to be offset 1 pixel to the left (-x) and one pixel up (+y). I am making a pixel perfect 2D game. (I have checked the "pixel perfectness" in photoshop and everything checks out. (E.G. My tiles are 64x64 and the Rect being drawn is 64x64.
Here is the code I am using to draw the Rect:
var pos = Camera.main.WorldToScreenPoint(selectorPos);
DrawQuad(Rect(pos.x-32,Screen.height - (pos.y+32),64,64),Color.blue);//TODO: Figure out why it's -31 not -32
function DrawQuad(position : Rect, color : Color) {
var texture : Texture2D = new Texture2D(1, 1);
texture.SetPixel(0,0,color);
texture.Apply();
GUI.skin.box.normal.background = texture;
GUI.Box(position, GUIContent.none);
}
Here are the results.
When Rect(pos.x
-31,Screen.height - (pos.y+
31),64,64),Color.blue);
we get the correct look:
When Rect(pos.x
-32,Screen.height - (pos.y+
32),64,64),Color.blue);
we get the mathematically correct but wrong looking result:
What am I missing here?
Answer by brent ragsdale · Feb 23, 2014 at 05:59 AM
Fixed it. I had my camera still adjusted 0.01 units to the right and down which I had turned off previously but the changes didn't save. (It was a temp-fix for half-pixel issues.)
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
changing a coroutine's argument at the coroutine's runtime? 1 Answer
Help scrolling puzzle is not. 0 Answers
Moving an object 0 Answers