Re-read J2ME game programming

Source: Internet
Author: User
Tags float double

Re-read J2ME game programming (2013.11.01)

decided to read it again J2ME game programming. This book is my 2005 purchase from Huangdao Xinhua Bookstore, that is the first time I heard that J2ME can develop the game on the mobile phone, immediately stunned, long can not leave, and then the corner of the bookstore holding this book greedy look, because this one, ridiculous afraid to be others first bought, the day spent the RMB79 purchase, This is the living expenses of nearly 10 days.

Reread the book, as the author of Martin.j.wells worship, but also because the book is the development of their own game of enlightenment reading. Although, from now on, the J2ME technology itself is outdated, the ideas, processes, steps, terminology, and technical essentials of game development included in this book are worth remembering.

Java's recipe for success is simply a word: Write once,run Anywhere. In my opinion, the predecessor of Java, the electronic device of star Seven, should have some foresight at that time. Just untimely, this is the same as the 2004 Nokia S80,s90 series, other environments do not reach, there is such a thing, no wireless signal, no internet, such equipment, to the current standard, really should not be called the next generation of computer technology.

Oak is better than Java, James Gosling Why not continue to use this name? The success of Java lies in the cross-platform implementation of the respective virtual machines on different platforms, and the use of a single language in the upper layer. Webrunner hooked up to the time of the Internet ticket, specific to the current Ios,android,winphone platform, why not continue to use this technology? What is the difference between Android's own Dalvik virtual machine and KVM?

Java's three branches j2se,j2ee,j2me, the current J2ME has fallen, in addition to some low-end Shanzhai machine MTK platform continues to use, seems to have been rare. J2SE also in the development of stumbling, scripted. Only the Java EE in enterprise-level development has enough knowledge and accumulation, is still the mainstream.

Java discards the multiple inheritance, templates, operator overloading, is really what most programmers hate, and just because of this, Java programmers become a popular, lower threshold of the occupation, but also become the people's eyes of the so-called code farmers.

Finally, there are tiny devices everywhere, and the prospects are still bright, and the portable equipment room is an exciting industry. For example, NOKIA s30,s40,s60,s80,s90 ... SONY ERICSSON MOTOROLA ... From this, the equipment is decentralized, fragmented, so the J2ME platform at the beginning of the design, according to the category to design, designed as "configuration" and "Summary."
Configuration: Abstract underlying description of a set of similar devices. CDC and CLDC
Summary: An abstract description that prefers the upper UI interface. Midp
In different configurations, Java has designed different virtual machines for them. For example, Hotspot VM,CVM,KVM. Designing different virtual machines is a right choice, and we cannot limit the compatibility to the lowest hardware devices, which is an unfair tradeoff for high-end devices.

J2ME security controls on Virtual machine security (pre-check) and application Security (sandbox).
Midlet:jar and Jad, notice the relationship between JAR and Jad, and why do you need to do this?

Finally, we can really use these limited resources to develop first-class games, and a great thing is not to sell souls to publishers to get a ¥ $2 million budget to develop a big game-if you can, creating a successful J2ME game requires just a few friends, The best is a bit crazy, when the project is completed, there will be a reliable way to achieve profitability.

Re-reading J2ME game Programming II (2013.12.09)

This content is J2ME Game Programming book Appendix of JAVA2 Review, although relatively simple, but can basic understanding of Java2 the whole picture.

A Java overview

Two Java program running mechanism

Three objects

1. Object description (State and behavior)/Java Object description

Data Description--data behavior--rendering layer

Car:{int x,int Y}-->move:{run X,y}-->paint:{setposition}

2. Instantiating a constructor domain method

3. Multiple constructors

4. Objects and Memory

Relationship of references and objects

There's no way to free up memory

Whether the object needs to be recycled by referencing if it is still useful to determine

Four basic syntax

1. Notes

2. Basic type Boolean byte char short int long float double, no unsigned

3. Common Types

Number: decimal = 128 binary = 126 binary =0x12 long integer =12l single floating-point =12f double floating-point =12d

Escape characters:

Value Assignment:

4. Operators

Assignment arithmetic bit operation (>> << >>>) conditional operation

5. Statements

Sequential condition Loops

Exception: Break label

6. Strings String

Question of whether strings are equal = = vs equals

String.valueof ()//numeric to String

7. Arrays

int array[];

int array[]={1,2,3,4,5,6,7};

array.length;//Array length

Five object-oriented programming

1. Inheritance

Extends

Super ()//Parent class constructor

Vector ()//data type Java1.2

instanceof//Judgment Example

Object.getclass (). GetName (). Equals ("...");

2. Overloading and rewriting

3.abstract

Virtual classes cannot be instantiated with dummy

Virtual method subclasses must be instantiated

4. Interface

5. Access Protection

6. Inner class

The inner class can access all the data of the encapsulated class without restriction, and the wrapper class cannot access the data of any inner class.

7. The destructor

void Finalize ();//Before garbage collection

8.this

cannot be used in the static method

9.static

Class Common Properties

10.final

Final modified properties and methods cannot be changed

Final-modified methods cannot be overloaded

Six anomalies

try{}

catch (Exception e) {}

Finall

Seven other

Package I

Re-reading J2ME game Programming III (2013.12.22)

The second part of the book is about the development approach and the use of basic APIs.
Although the visual integration development environment is more friendly and convenient, the command line approach allows us to understand how the application is run. In J2ME, it is divided into three steps:
1.javac compilation
2.preverify Pre-calibration
3.MIDP operation

J2ME in the design of the API is divided into Application,timer,network,rms,ui five parts.
On the application side, a MIDlet is an application, an application controlled by jam. MIDlet's API features are divided into 2 main areas, namely Jam tells MIDlet some things, midlet tell jam some things.
Timer, divided into timer and timertask. There is nothing special here, and the inside of J2SE is consistent.
Network, the use of a set of frameworks called GCF, the use of Factory mode.
Data preservation, the use of a simple RMS system, are relatively simple, there is nothing more to say ...
Next is a piece of big head, UI.
The UI consists of a high-level UI (screen) and a low-level UI (Canvas). The only one displayable displayed on the display. In screen, List,textbox,alert,form.form is a special control and a collection container for other controls. In the canvas, we use the graphics to draw an image on the canvas.

There are two more interesting questions.
What is a variable image and an immutable image? An image that cannot be modified is immutable, otherwise it is mutable.
The other one is what is double buffering? Instead of drawing directly on the screen using the Graphics tool, first create a picture, get the graphics of the picture on it, then draw on it, and finally, paint the picture on the screen at once.

Although here mainly to MIDP1.0 to explain, but, believe me, again MIDP1.0 on the accumulation of development experience will not be thrown, in MIDP2.0 most can continue to use, and have better features.
In fact it does.

Re-read J2ME game Programming IV (2016.01.04)

The following author, with a small game example, explains the basic framework of a game and the use of J2ME commonly used APIs, which is a very popular version of the daily crossing of the road last year.
The core of a game, in fact, is a game loop, this cycle of every time, all the tasks are done again, to fast enough, so that the player seems to have a sense of realism, like playing a movie, play a movie is 24 frames per second, that is, every second 24 cycles, the game may need faster, no matter what game, The basic structure is as follows:
void Run ()
{
Input ();
Logic ();
Paint ();
Calculate FPS
if (curtime-lasttime>1000)
{
Lasttime=curtime;
Out ("FPS");
fps=0;
}
Else
{
fps++;
}
PFS can be obtained through FPS, that is, the time of each frame, and then through the time operation, you can find out whether there is time remaining, some words can sleep threads.
fps=24;
Pfs=1000/fps;
if (CURTIME-LASTTIME&LT;PFS)
{
Sleep (pfs-(curtime-lasttime));
}
Note that the above two FPS and PFS are two different scenarios
}
In the logic loop, there is a problem, how to solve the game loop movement logic without floating point number? The practice of this book is: to 100ms as a rendering unit, assuming that about 20ms is a game loop, each cycle, the dtime of this loop is added, when reaching 100, the start of a rendering. Then if there is time left, accumulate records. Until the next 100ms is saved.
This is the general structure of the game, the White is a big loop. Finally, let's familiarize ourselves with the general structure of game rendering.
1. First, there is an application manager, inside the J2ME is the Jam,midlet, which has the application of the program's entrance and exit.
Appmanager.java
Start ()/pause ()/exit () ....
2. There should be a game menu Menu.java, where the various portals of the game interface are placed.
3. Game scene Gamescene.java, game scene, game main loop (i.e. the loop at the beginning of this article) here. The main loop of the game looks at whether the requirement is to expand independent threads.
void Run ()
{
while (true)
{
...
}
}
Here the bread contains all the actors ' logical processing and rendering, using interfaces. Note that double buffering is used here.
void Paint ()
{
Vector...paint ();
Arraylist...paint ();
}

4.actor.java. Actors, that's what we call Elves. Actors have their own logical operations and rendering.
void ticker (float dtime)
{

}

void Render ()
{

}
5. Collision Detection: Rectangular collision

Re-read J2ME game Programming Five (2016.01.21)

In the third part of the book, the author uses the API provided by J2ME to do a detailed game, named Star Assault, the Chinese name is called Space War. This is a game example, but from another point of view, it has two functions. The first is that the author uses the MIDP1.0 API to implement the MIDP2.0 game Library API. Second, on the whole, the project implements a simple 2D game engine with at least a rudimentary engine model. Starting with this section, we'll review how to make a simple game engine by reading this project again.
The first is the realization of the elves we are going to say. The genie is a main body of the game content, is an indispensable part, it is implemented by the following code structure.
1. Picture packing, hashing and concave.
This time in the Cocos engine is very common, that is, a lot of scattered images packaged in a picture, but in the J2ME era is much more humble, at least in this project, all this is orderly, do not need to plist description file.
2. Load the image, where the image is the Datum origin in the upper-left corner.
void LoadImage (String filename);
2. Image clipping, using a concept, previously mentioned variable images and immutable images, we put the immutable image on the variable image, completed the image clipping.
Image getimageregion (image source,int x,int y,int width,int height);
Take part of the source image, start with the X, Y point and go to width,height size, and return the new picture.
3. Detach the frame, since the method above can take part of the picture, we can think of one frame at a time and then save it.
Image[] Extractframes (Image source,int x,int y,int wide,int high,int width,int height);
The parameter has the same meaning, except for the number of frames in the x, Y direction respectively.
4. Image set, in fact, is the multi-state of the spirit of the collection, each state has a corresponding image[]
Imageset.java
numstates;//State number
stateframewidth[numstates];//State Frame width
stateframeheight[numstates];//State Frame Height
stateframes[numstates][];//status and number of frames? Review one-dimensional arrays and two-dimensional arrays
Addstate (Image frames[],int anitime);//Add state and time, in fact this is the most critical method in this step
void Draw (Graphics g,int state,int frame,int x,int y);//Draw Frame
5. The wizard, the wizard and the image set why separate, the author did not elaborate, but the image loading and physical rendering separate, it seems to be necessary.
Sprite.java, the most attention is animation processing, here we used to say the cycle (float DT), the time interval to determine whether to change frames
curstate;//Current status
curframe;//Current Frame
Sprite (ImageSet set,int state,int frame);//initialization
setState (int state,bool force);//state toggle, whether forced
6. Possible improvements
Animation Reverse Playback
State self-switching
Event triggers
Image Set Management
Resource Data visualization

Re-read J2ME game programming

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.