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!
Related
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)
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,
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.
I'm trying to figure out how to draw text in 3D.
Right now I have two ways to display stuff onto the screen. One that uses usual 3d space to render the world, and additional render to render the HUD that does it in pretransformed way.
So, ideally I would like a way to do the same for text, to both render a string in 3D (kind of like "billboarding" way) and pretransformed way (as if I was using 2d mode).
The only thing that I was able to find is to use "Mesh.FromText", but it doesn't seem to be what I need. Oh, and also using spritebatch to draw text to a texture, and then using this texture in 3D with alpha blending, but again it seems like a crappy way to do it...
Any ideas?
You can draw with SpriteBatch in 3D space by using a custom effect. This blog post has the details.
It's as simple as passing an effect (like BasicEffect) with the correct transformations set on it to the appropriate overload of SpriteBatch.Begin (this one).
(The text is made up of transparent sprites - so all the usual caveats with drawing with transparency in 3D apply: sort and draw over the opaque, Z-buffered scene, or use alpha-testing.)
I'm creating a paint like application using XNA.
I have a render target which acts as a canvas. When the user draws something I draw corresponding triangles using DrawUserPrimitives and triangle strips to make lines and other curves.
I want to implement an eraser in the application, so that the user can erase the triangles from the texture. I've used OpenGL in the past and there I would just use a blend function like so: glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
How would I do this in XNA? I tried setting the GraphicsDevice blend mode to AlphaBlend, Additive, etc.. but it did not work. Any ideas?
If you change your code to use a Texture2D instead of a RenderTarget2D, you can use RenderTarget2D.GetTexture() to get the pixel data from the RenderTarget2D.
Of course, there will probably be a performance hit, but if you can optimize the code in a way that cuts down on the number of times this is done, like temporarily drawing the background color instead of actually erasing, and then iterating through the pixels after the mouse is released, you could make it work.
There may be a better way, but I couldn't find it.