1. Genie and 2D graphics
1. What is 2D?
2D can be understood as two-Dimentionanl, short for 2-dimentional.
It means two dimensions. For example, the Cartesian coordinate system in mathematics can describe a 2D plane.
Generally, a display screen is displayed on a computer.
When you are facing the display, the upper left corner of the display is the origin of the Cartesian coordinate system. The coordinates are (0, 0)
So what about the X axis? the X axis is the top side of the display, and its positive direction is your right side.
The Y axis is the left side of the monitor, and its positive direction is downward.
2. What is a genie?
Simply put, it is the image drawn on the screen.
To put it bluntly, there are basically a lot of images.
2. display the genie on the 2D Screen
1. As mentioned above, the game basically draws pictures on the screen. Let's get started.
- In the Game1 class of the newly created Project, note the following:
Since you want to draw genie, you always have to do it,
GraphicsDeviceManager graphics;
That is to say, call a manager who has a good relationship with the video card and prepare to draw a genie.
- However, as mentioned above, there are a lot of genie in 2D games, so let this manager
It is estimated that there are so many elves dealing with each other. Is it necessary to select a shift leader?
Team lead or something. How can I manage the class? That's of course.
Read this sentence:
SpriteBatch spriteBatch;
This is called a senior Genie who specifically manages the genie.
- If you have a manager and a group leader, no one will perform on the stage!
The following performers are coming soon:
Texture2D texture;
In this case, a performer is hired. Now the people are here.
The audience can't wait until there are few idle talk. Let's get started. But there is another problem,
That means actors have to dress up, or they cannot get on stage!
- The following is a makeup for the actors:
Use cosmetics first:
In the solution, <Content> right-click and choose> Add existing item> select an image)
Start makeup:
This is an action to add to the corresponding Game1 class method, that is, the LoadContent method:
Texture = Content. Load <Texture2D> ("PictureName ");
On the stage, you can use Draw as follows:
GraphicsDevice. Clear (Color. CornflowerBlue );
This is to clear the video card first, because there will be something left behind in the last performance.
Then, pull the canvas.
- Next, let the genie leader start to ask:
SpriteBatch. Begin ();
- Next, let's really ask people:
SpriteBatch. Draw (texture,// <----- Texture is the called person
GraphicsDevice. ViewPort. Bounds,// <------- Position
Color. White)<------ The color of the masked gauze, which is not masked here, appears directly.
- When people are finished, the following message is displayed:
SpriteBatch. End ();
After all the actors are on the stage, start the big show! Run the game and you will see
They are already on the stage: