I really can't wait? Plus, let us join the protagonist airplane. You can position this game in action game, one action game requires constant input from the user, basically uninterrupted, so Plane needs constant change position. So how should this 游戏 桢 游戏? This requires testing in the phone, on the simulator, if it is about 15-18, it is appropriate. Listening to several XDs that 9CBS says only in 12 桢, different games are not necessarily. Basically, the requirements of the game on the machine are a little higher. Our game framework is linear, that is, the output display and acceptance input is in the same thread, 15 below the game processing input will appear to be more benzene, higher than 20 桢 If the processor speed is slow, it is easy to appear input card The buffer, which is noted. At this stage, try to make the number of numbers, you can't program the same as the PC, and the situation of the 30fps is compared with the case.
In this game that controls the wizard as the main content, we do not package any game events, and our programs may be somewhat tender, no relationship, step by step.
Aircraft
Plane is a standard Plane. Composed of three screens:
In the constructor, we join the initialization object statement of the aircraft:
Image img = imagetools.getiMage ("/ pic / myplaneframes.png");
Plane = New GameObject (IMG, 24, 24);
In Gameinit () in the initialization state, the location is in:
Plane.Reset ();
Plane.moveto (ScreenWidth-Plane.Sprite.GetWidth ()) / 2 (ScreenHeight-Plane.SPRITE.GETHEIGHT ()) / 2);
Add: GameMain
Plane.Paint (g);
Next, let the aircraft moves under control, mainly to add input processing in GameMain, if the plane is left to update the screen to the left of the plane, if the plane is right, let the aircraft is normal.
IF (GameOver) {
} else {
IF (keyevent) {
IF (Key_up) {
Plane.move (0, -3);
Plane.sprite.setframe (0);
}
IF (Key_Down) {
Plane.Move (0, 3);
Plane.sprite.setframe (0);
}
IF (Key_left) {
Plane.move (-3, 0);
Plane.SPRITE.SETFRAME (1);
}
IF (key_right) {
Plane.move (3, 0);
Plane.sprite.setframe (2);
}
IF (key_fire) {
}
}
}
Else {
Plane.sprite.setframe (0);
}
}
Although it is very simple, this is the main way of controlling the movement of the elves. You can imagine it, if you don't have a simple picture, how to achieve animation? Our GameObject function is limited, no enhancement of the animation sequence of Spriite, in the future, we can enhance GameObject to support multiple animation sequences, make up for the shortcomings of Spriite. Now gradually realizing how important a good game engine is ...
2. Background
Let the plane fly in the sea, we represent the sea with a blue background image, we need him full background. We use TileDlayer to paint background.
initialization:
IMG = imagetools.getimage ("/ pic / back_water.png"); int backcolumns = screenwidth / img.getwidth () 1; // Computing landscape
INT backRows = ScreenHeight / Img.getHHEIGHT () 1;
Background = new tiledlayer (backcolumns, backrows, img, img.getwidth (), img.getHeight ());
INT X, Y;
For (int i = 0; i X = I% backcolumns; Y = I / backcolumns; System.out.println ("x =" x "y =" y); Background.setcell (x, y, 1); } Next, add a plot statement in GameMain. Background.Paint (g); // Draw Background Note that before the background of the background drawn to the plane of the plane. If you use the LayerManager to control the drawing layer, our next bullet requires multiple bullets to share a sprite image, but when LayerManager is painted, you will call the LayerManager's Paint by LayerManager, So only supports a Sprite in one place, so I think LayerManager has some chicken ribs. Generally, we still put it yourself. Of course, the layer is a very important concept, using the layer, the screen calibration will be very convenient, and the special effects of shaking the entire screen will be realized. Maybe you have a good method, you can make me not in the contradiction between the LayerManager layer and the Sprite status object group ... Greeting, our plane moves, haha, let us look forward to joining the bullet, it is the "essence" of this game.