tiled draw mode in Sprite Renderer component - c#

Illustrating Image:
Ok so my goal is to fill up the sky with blue. I used the tiled draw mode in Sprite Renderer component but it doesn't seem to be a good choice. I thought of creating a blue square and then put it on top of the sky but is there any way to do it automatically? ( I found something called border but I couldn't understand what these green lines mean? )

You first have to set up the image to tile correctly. In the inspector for the image you want to tile, open the Sprite Editor, and move the border (green box) to select the SKY portion of your image. For example:
After doing this, your sprite should tile correctly:
Do Note:
If you're filling in a solid color for the sky, use the Sliced mode instead of Tiled to reduce polygon counts. (Tiled mode will make new quads for each repeated section, while Sliced will stretch the solid color in only one quad):
(Left is Tiled, right is Sliced)

Related

Sprite Renderer in Unity2D not functioning

View of the Inspector for the Tile prefab
Tile script
Grid Manager script
I am attempting to generate a grid of squares that form a checkerboard pattern. When line25 of the Grid Manager is removed, it generates a plain white grid perfectly fine, but when I do run init to introduce the checkerboard colors, all of the sprites do not render and the tiles are invisible. The colors are assigned to the tiles when they are generated, but the Sprite Renderer is not drawing them.
Expectation: Running init should assign the colors to the generated tiles, making a checkerboard pattern instead of a plain white grid.
Result: Running init assigns the proper colors to each tile, but the Sprite Renderer doesn't render them anymore, resulting in a blank Scene view and Game View
Your colors have an alpha of zero. In the inspector, at the bottom of the colors, you can see a black line. This fills up with white as it is set to be less transparent. You can click on it and set the alpha, or in the script you can set the .a on the color to 1.

Weird screen scaling and sprite displaying

When i scaled my window, the sprites were a lot smaller, also, sprites do not display after reaching about halfway across the screen. The background color blue still displays but the sprites get cut off.
In the above image as you can see the sprites did not stretch with the screen, and the sprites near the top are being sliced when they reach that part of the screen.

How to animate alpha in an image in Unity?

Ok, I don't know if this is possible but I need to animate the alpha portion of an image - like I have an image with a shape cut out of it so the background shows through, and I want to animate the size of this hole in Unity;s animation controller.
I know it is possible to animate images by stringing together a series of different images like sprite animation, but I want to know if there is a way to animate or cut a hole in another image using an image in Unity and/or animate the alpha portion.
Is this possible? An example of an alpha image with hole cut in it:
And I would want to scale/animate that cut out inner square.
In unity, you can animate everything that can be changed in the inspector, including the size and color (including alpha) of your sprite.
However, it is not possible to animate pixels of a sprite seperately, as far as i know, meaning that you cannot change the alpha value of an area inside your sprite.
Do your images consist of a single color only or do you use complex images?
Well I guess the Shader you can find here will the closest answer to your question.
Other than that, operations on your texture will be quite heavy to perform at runtime.
Hope this helps,

Lighting covering up sky

I have a 2D tile-based lighting system which is drawn onto a Render Target.
I am also drawing a background which involves mountains, sun/moon, and clouds.
There is also the unlit game; blocks, character, etc.
Here is the order in which everything is drawn:
1. Background
2. Game World
3. Lighting
The problem is that the LIGHTING is covering up the BACKGROUND when it's dark:
Although it's perfectly fine in the day because the light is full:
You might ask, well, why don't you just blend each block, not drawing the lighting on a RenderTarget?
Because that would prevent me from performing smooth lighting, as seen in the pictures. To produce the smooth lighting, I draw squares of light onto a RenderTarget, perform a Gaussian blur and then draw that RenderTarget.
How about not drawing a square of light in empty spaces?
The light blurs onto any adjacent blocks, and not all objects in my game affected by lighting are square, so they would look like a sprite with a blurry square on top of it.
Light NOT being drawn in empty spaces:
Light being drawn everywhere:
Is there any way to keep the background visible, or something else that would help my predicament?
I'd suggest you do the following:
Render lighting to rendertarget
Render scene to rendertarget (leave the background transparent)
Multiply scene with the lighting rendertarget
Render background to screen
Render scene (with the lighting already applied) to the screen
Because the background is added after applying the lighting, it will not be affected.

C# MDX drawing transparent rectangle over a sprite

I want to make a "Pausemenu" in a Tetrisgame, when I hit Esc, the Menu pops up and that the user clearly is aware of that the game isnt running, I want to draw a transparent black rectangle over the whole game sprite, I´m using C# Managed DirectX 9.0c on .Net Framework 3.5. (I could achieve the same effect with a texture, but since in the settings the Board Width/Height can be changed, this would be an ugly solution)
Is there an easy way to achieve this?
You can simple create a small PNG, make it black and 75% opaque.
In your Game just use the Sprite Class (with alpha enabled) and scale it (with transform) to the dimensions of your viewport.
You could also use the Sprite Class to modify the Color of the Sprite when drawing, so you can make it fade in or out or give it another color.
Hope that helps!

Categories

Resources