अगर मैं का उपयोग निम्नलिखितक्या कोई अल्फा मान है जो सफेद को अदृश्य बनाता है?
for(int i = 255; i > 0; i--)
{
Color transparentBlack = new Color(0, 0, 0, i);
}
मैं इस रंग का उपयोग वस्तु के प्रभाव काला से एक हल्के भूरे रंग के लिए जा रहा है और फिर अदृश्य जब अल्फा मूल्य शून्य करने के लिए चला जाता है के साथ आकर्षित करने के लिए किया है। हालांकि अगर मैं एक सफेद मूल्य से शुरू करता हूं:
new Color(255, 255, 255, i);
वस्तुएं अदृश्य हो जाती हैं और केवल सफेद रहती हैं। मैंने यह भी देखा है कि यदि मैं एक ऐसे मान का उपयोग करता हूं जो काला से थोड़ा हल्का है (50, 50, 50 कहें) तो चित्र अंधेरे से, अदृश्य, सफेद तक जाता है।
मुझे लगता है कि मुझे समझ में नहीं आता कि अल्फा ब्लेंडिंग मिश्रण कैसे काम करता है लेकिन क्या अनुवाद के लिए एक सफेद रंग फीका बनाने का कोई तरीका है?
संपादित करें: नमूना XNA स्पष्टीकरण प्रजनन कार्यक्रम: पृष्ठभूमि मैं पर ड्राइंग हूँ Color.CornflowerBlue (100.149.237.255)
संपादित है। काम में लाना; एक नया XNA खेल स्टूडियो 4.0 परियोजना बनाने - विंडोज खेल (4.0), फोन यह AlphaBlendTest - & सामग्री परियोजना में एक नया SpriteFont जोड़ सकते हैं और फोन यह testfont
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace AlphaBlendTest
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("testfont");
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
//spriteBatch.Draw(tR, new Rectangle(100, 100, 100, 100), Color.Red);
Vector2 v2 = new Vector2(0, 0);
spriteBatch.DrawString(font, "Test - White", v2, Color.White);
v2.Y = v2.Y + 50;
spriteBatch.DrawString(font, "Test - Black", v2, Color.Black);
v2.Y = v2.Y + 50;
Color BlackTransparent = new Color(0, 0, 0, 0);
spriteBatch.DrawString(font, "Test - Black Transparent", v2, BlackTransparent);
v2.Y = v2.Y + 50;
Color WhiteTransparent = new Color(255, 255, 255, 0);
spriteBatch.DrawString(font, "Test - White Transparent", v2, WhiteTransparent);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
संपादित करें: यह चित्र इस कोड खींचता है:
संपादित करें: टिप्पणियों में से एक चिंतित है कि यह एक पाठ केवल विंडोज़ से संबंधित 'फीचर' है। मैंने डेमो प्रोग्राम को छोटा रखने के लिए एक उदाहरण के रूप में टेक्स्ट का उपयोग किया; एक छवि के साथ परीक्षण एक ही परिणाम देता है।
डेमो प्रोग्राम में स्क्वायर बॉक्स जोड़ने के लिए; एक वर्ग सफेद पीएनजी छवि बनाएं और इसे सामग्री निर्देशिका में जोड़ें (सामग्री पाइपलाइन के लिए डिफ़ॉल्ट मान का उपयोग करें)।
Texture2D tWhiteBox;
लोड विधि करने के लिए इस जोड़ें::
v2.Y = v2.Y + 50;
spriteBatch.Draw(tWhiteBox, v2, WhiteTransparent);
अब आपको बेहतर जवाब मिल गए हैं, मैं अपना हटाना चाहता हूं ... लेकिन सिर्फ यह जांचने के लिए, क्या यह टेक्स्ट * के अलावा अन्य वस्तुओं के साथ भी होता है? –
हां; मैंने उदाहरण में ड्रॉ स्ट्रिंग का उपयोग किया ताकि मुझे सरल परीक्षण कार्यक्रम के लिए एक बनावट अपलोड करने की आवश्यकता न हो ;-) इसका परीक्षण करने के लिए मैंने एक छवि का उपयोग किया जो सिर्फ एक सफेद बॉक्स है और फिर विभिन्न रंगों का उपयोग करके इसे खींचें ड्रॉ स्टेटमेंट फिर इसके रंग को बदल देगा। –