Using NetBeans for J2ME Development (v): Unlocking the mysteries of game development

Source: Internet
Author: User
Tags netbeans

Game development, a very big proposition oh. Whether it is the game's plot design, or the game's art production, that is not one or two can be done, and programming, but only a small part of it. However, even this small part, I can not grasp it very thoroughly. This essay is mostly transcription, mostly for the integrity of my blog, but I still try to write it so that those masters who are proficient in other areas of Java but have no chance to do J2ME development look at the picture solution Jiejie, Let those who want to do mobile game development to see what the J2ME Game API provides us with what support, let us know what to write games to understand what concepts.

To learn about MIDP 2.0 's game development Kit, don't be afraid, this set of APIs is very concise, only a few 5 classes, they are located in the Javax.microedition.lcdui.game package. They are Gamecanvas class, layer class, Layermanager class, Sprite class and Tiledlayer class respectively. Here are a few different uses for each class.

1> Gamecanvas Class

The Gamecanvas class is a subclass of canvas, which represents the basic interface of the game, and, simply put, all game images are plotted on the Gamecanvas. So what are some of the more advanced features that Gamecanvas and canvas offer? There are two main points: 1, realize double buffering function; 2. Provides a way to poll keyboard input events.

Double buffer you must be very familiar with, that is, when we draw the image of the first drawing into a buffer, and so on, and then once the image is finished, and then display to the screen, so that it can effectively eliminate flicker and screen tearing phenomenon. In Gamecanvas, we can get the Graphics object instance of the buffer through the Getgraphics () method, and the contents of the buffer can be displayed on the screen through the Flushgraphics () method.

What's the use of polling for keyboard input events? To answer this question, we first need to understand some basic game framework, in most games, there is a main loop, this main loop determines how many steps our game runs per second, and in each step, the first query has no keyboard input events, Then run the logical operation of the game, the last update screen, and then into the next step. In canvas, the keyboard input events are done through callbacks, that is, when there is a button to press, call the Keypressed () method, such a function will not be able to meet every step we have to query the keyboard input requirements. You can poll the keyboard by calling the Getkeystates () method.

2> Layer Class

This is an abstract class, and we don't use it directly, but we use its two subclasses--sprite class and Tiledlayer class

3> Sprite Class

Sprite is the meaning of the Elves, this is a game development of the proper noun, in our game each object, we can be called an elf. The Sprite class provides a screen rollover, rotation, and simple collision detection. It's also easy to draw a Sprite object on the Gamecanvas, just call the sprite paint method, which requires a graphics type of argument, and we pass the Graphics object instance of the buffer to it.

4> Tiledlayer Class

Tile is also a two-dimensional game development of the classic vocabulary, is the meaning of bricks. What's the use of this class? It's mainly used to build maps. This reason to think it is easy to understand that we play in the game, the map is often much larger than the screen window, do we need to do such a large picture? Of course not, we only need to do a few small pictures, it these pictures in a certain order to tile, you can get a fairly large map. The Tiledlayer class provides us with this functionality.

5> Layermanager Class

This class is mainly used to manage layer, it can be layered on the canvas to draw the wizard and map, so that it can be more convenient to solve the former, who after, who blocked who and so on.

Here's a look at the example. As has been said, game design is a very complicated process, no professional team is difficult to do. Of course, we are not no alternative to the way, that is pirated. Think about the classic games we've played since we were kids? Tetris, Super Marie, Alloy warheads, Thunder, Street Fighter, boxing emperor and so on, there are two years ago very popular "is the Man series", these games each have their own operating platform, and later most of the porting to the PC platform, now, Why don't we try transplanting them onto the phone? Through the previous introduction, it is not difficult to see, these classic 2D games can use the above several classes to generalize: airplanes, bullets, enemies are Sprite, the sea, the sky, forests, deserts are tilelayer, we face the problems, is to collect and make the picture material just.

The example here is "men on the next 100 layers" of the mobile phone, download address: http://www.j2medev.com/Soft/src/game/200610/802.html, the author is not known, anyway, not me. The following is a chart of the effects of the operation:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.