- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Setting a Color Value in .NET framework
Setting a Color Value Painting QR-Code In Visual Studio .NET Using Barcode creator for .NET Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications. www.OnBarcode.comQR Code ISO/IEC18004 Scanner In .NET Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comYou now have a variable that can hold the color of your background. At the moment, it is not set to anything useful. So next, you have to write a statement that causes the game program to put a value into this variable. You start by creating a new Color value that contains a Encoding Bar Code In Visual Studio .NET Using Barcode drawer for .NET framework Control to generate, create bar code image in .NET applications. www.OnBarcode.comReading Barcode In .NET Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comPart I Getting Started
Draw QR Code In Visual C#.NET Using Barcode creation for .NET Control to generate, create QR Code ISO/IEC18004 image in VS .NET applications. www.OnBarcode.comEncoding QR Code In VS .NET Using Barcode creation for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications. www.OnBarcode.comparticular amount of red, blue, and green. Figure 2-4 shows the anatomy of an assignment that makes a new Color value and then places it in the variable. Quick Response Code Maker In VB.NET Using Barcode creation for .NET Control to generate, create QR Code ISO/IEC18004 image in VS .NET applications. www.OnBarcode.comGTIN - 13 Printer In VS .NET Using Barcode creation for Visual Studio .NET Control to generate, create GTIN - 13 image in .NET framework applications. www.OnBarcode.combackgroundColor
Making Code 128C In Visual Studio .NET Using Barcode generator for VS .NET Control to generate, create ANSI/AIM Code 128 image in .NET framework applications. www.OnBarcode.comEAN128 Drawer In .NET Using Barcode maker for .NET framework Control to generate, create EAN / UCC - 14 image in VS .NET applications. www.OnBarcode.comnew Color (0,0,0); Generating Barcode In .NET Framework Using Barcode printer for VS .NET Control to generate, create barcode image in .NET applications. www.OnBarcode.comUniform Symbology Specification Code 93 Creation In VS .NET Using Barcode creator for VS .NET Control to generate, create Code 93 Extended image in .NET applications. www.OnBarcode.comVariable identifier
QR Reader In Java Using Barcode scanner for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comUSS Code 128 Encoder In VS .NET Using Barcode printer for ASP.NET Control to generate, create Code 128 Code Set B image in ASP.NET applications. www.OnBarcode.comEquals or Gozzinta
Painting Bar Code In .NET Using Barcode encoder for Reporting Service Control to generate, create bar code image in Reporting Service applications. www.OnBarcode.comUSS Code 39 Printer In None Using Barcode creator for Online Control to generate, create Code 3/9 image in Online applications. www.OnBarcode.comExpression
Generate Barcode In .NET Framework Using Barcode generation for ASP.NET Control to generate, create barcode image in ASP.NET applications. www.OnBarcode.comQR Code JIS X 0510 Generation In Visual C# Using Barcode generator for Visual Studio .NET Control to generate, create QR Code image in VS .NET applications. www.OnBarcode.comFIGURE 2-4 Ass gn ng a new Color va ue to backgroundColor.
ANSI/AIM Code 128 Generator In Visual Basic .NET Using Barcode encoder for Visual Studio .NET Control to generate, create ANSI/AIM Code 128 image in .NET applications. www.OnBarcode.comMaking QR Code JIS X 0510 In None Using Barcode encoder for Microsoft Excel Control to generate, create Quick Response Code image in Excel applications. www.OnBarcode.comThe thing that is going to be assigned is on the right side of the equals sign. In this case, you are making a new Color value. Don t get this confused with a double-equals that might be used to compare two things. You should regard the equals sign in Figure 2-4 as being what I call a gozzinta operator. The value on the right of the equals sign goes into the variable on the left. You will investigate how to compare things later in this chapter, in the section Making a Proper Mood Light. Now that you have your variable, you can use it in the game program: GraphicsDevice.Clear(backgroundColor); The preceding statement calls the Clear method and feeds it the value of backgroundColor. This causes the screen to be cleared to the new color you created. If you put these statements together, you get a game program that contains a backgroundColor variable that is used by the Draw method, which sets it to a value and then clears the screen using it: protected override void Draw(GameTime gameTime) { Color backgroundColor; backgroundColor = new Color(0,0,0); GraphicsDevice.Clear(backgroundColor); base.Draw(gameTime); } If you want to find out what color you get if you make one with no red, no green, and no blue, you can run a program that uses this Draw method. But I don t think I m giving too much away when I tell you that this would produce a black screen. The actual color values are given in the order red, green, and blue, and each must be in the range 0 to 255 (you shall learn the reason for this later). By using different values when you set the Color, you can experiment with different displays. The color combinations obey all the rules of color combinations (for light, rather than for paint) that you would expect: backgroundColor = new Color(255, 255, 0); The preceding statement sets backgroundColor to a color value that has the red and green values at maximum, which would be displayed as yellow. 2 Programs, Data, and Pretty Colors
Sample Code: Yellow Screen of Peril The samp e project 02 MoodL ght Ye ow
Background creates a ye ow background co or and fi s the screen w th t You can change the numbers n the Draw method to make any co or you ke Controlling Color
At this point, you can see that we can add C# statements to the Draw method to change what is drawn on the screen. You also know that XNA uses a Color structure to lump together information that describes a particular color and that you can create your own Color variables in the game that contain a specific amount of red, green, and blue. Finally, you have managed to make a program that uses a color variable to set the screen to any color that you like. Next, you want the light to change color over time, to get a nice soothing mood light effect. This sounds like hard work (and like every great programmer, I really hate hard work), but actually it turns out to be quite easy. To discover how to do this, you have to find how XNA is connected to the game programs that you write. The way this works uses C# classes.
|
|