1. Coordinate System in Android
In Android, the upper left corner of the screen is the coordinate system's origin () coordinate. The point of origin is to the right of the X axis, and the point of origin is to the right of the Y axis.
2. Screen width and height
To draw a graph at a proper position on the screen, we need to use the width and height of the screen as a reference to determine the position of the drawing. To obtain the screen width and height, first obtain the windowmanager object from the activity object, then obtain the Display object from the windowmanager object, and then obtain the screen width and height from the display object.
// Obtain the screen width and height
Windowmanager manger = getwindowmanager ();
Diaplay = manager. getdefadisplay display ();
Int screenwidth = display. getwidth ();
Int screenheight = display. getheight ();
3. Confirmation of boundaries
In many games, you need to determine the boundary of the view drawn on the screen. For example, in a shooting game, we need to determine the boundary positions of views such as players, enemies, and bullets. The boundary judgment is nothing more than the upper, lower, left, and right screen boundary judgment.
If the X coordinate of the current view is less than zero, the current view is out of bounds on the left. If the X coordinate of the current view is greater than the screen width, the right is out of bounds.
If the Y coordinate of the current view is less than zero, the current view is out of bounds. If the Y coordinate of the current view is greater than the screen height, the lower part is out of bounds.
4. View Movement
The implementation process of the game is actually very simple, that is, not only changing the coordinates of the view, and then re-drawing them on the screen. However, the location change and Drawing Process of such coordinates are controlled by some logic. The movement of a view is achieved by changing the Coordinate Position of the view. After the coordinates are changed, re-draw the chart. We feel that the view is moving.
If the view moves horizontally to the left, the X coordinate decreases. If the view moves horizontally to the right, the X coordinate increases.
If the view vertically moves up, the Y coordinate decreases. If the view vertically moves down, the Y coordinate increases.
5. Basic android game development framework
There are three basic objects in the android game development framework: one is the layer object, which defines the width and height of the layer, the position of the layer, the movement of the layer, and the method of drawing; second, view objects are used to draw layer objects, corresponding Keyboard Events, and view threads. Third, an activity controls the game process, for example, start a game, pause a game, and stop a game.