Develop a game with MIDP2.0 (3) Add background and prospects

xiaoxiao2021-03-06  73

Last time we have made the tank, now we are ready to add background and prospects to the game.

The last discussed animation with Sprite, in fact, background and prospects are also implemented with Sprite, we prepare a background and a foreground picture:

Note that the background can be opaque, but the prospect must be dealt with a transparent PNG format (all over the JPG screenshot, please use Photoshop and other translations).

Modify TANKGAMECANVAS as follows:

public class TankGameCanvas extends GameCanvas implements Runnable {... private Sprite spritePlayer1; private Sprite spriteBackground; private Sprite spriteForeground; public TankGameCanvas () {... try {Image image = Image.createImage ( "/ res / img / player1.png" ); Spriteplayer1 = new sprite (image, 16, 16); spritebackground = new sprite ("/ res / img / bg.png"); spriteforeground = new sprite (Image.createImage ("/ c m /FG.PNG "));} ...} ...}

Then draw Sprite in turn in the DrawScreen () method:

Private void DrawScreen (Graphics G) {spritebackground.paint (g); spriteplayer1.setposition (currentx, currenty); spriteplayer1.paint (g); spriteforeground.paint (g); flushgraphics ();}

OK, the effect in the simulator is as follows:

Next, we are ready to write the game core, including the representation of map data, collision processing, timer's implementation, simple AI, etc., I hope everyone will continue to pay attention and support!

:): ~ * o * ^ _ ^

转载请注明原文地址:https://www.9cbs.com/read-121430.html

New Post(0)