Hello,
what I am trying to do is the following:
I want to draw an array of Bullets onto a RenderTexture. This Texture is then used for a Button.
This is so the user can choose between three different patterns of Bullets.
Displaying the texture on the Buttons is no Problem. However Drawing onto the Texture gives really weird results.
Here’s my Code for Drawing the positions onto the texture:
preview [patIdx] = new RenderTexture (256, 256, 0);
preview [patIdx].enableRandomWrite = true;
preview [patIdx].Create ();
RenderTexture.active = preview [patIdx];
float halfsize = bulletPreview.width / 2;
for (int i = 0; i < shots; i++) {
float x = (positions [i, 0] + 0f) * 2f / 6f;//+3*256/6
float y = (positions [i, 1] + 0f) * 2f / 8f;//+4*256/8
Graphics.DrawTexture (new Rect (x - halfsize,
y - halfsize,
halfsize * 2,
halfsize * 2),
bulletPreview, null);
}
RenderTexture.active = null;
halfsize is half of bulletPreview’s width/height. This gives me an empty Texture.
If I change the Rect to
Graphics.DrawTexture (new Rect (-1f, -1f, 2f, 2f), bulletPreview, null);
bulletPreview gets drawn over the entire texture, so apparently the coordinate space for rect goes from -1 to 1 even though DrawTexture’s Documentation states otherwise.
This would be no problem if I could just scale my coordinates into [-1,1] but it gets rounded/floored to the nearest integer, so i can only chose onto which quarters of my RenderTexture I can draw.
If this explanation is unclear, please let me know and I’ll try to show examples.