Getting started with the j2_2d games (3) control plane movement

Source: Internet
Author: User

Can't you wait? Let's join the game's leading aircraft.
 
You can position this game in an action game. An action game requires constant input from the user end, basically uninterrupted, so plane needs to constantly change its position. So how many suitable should this Compaction-based game be? This needs to be tested on the mobile phone. On the simulator, if it is set to around 15-18 Gb/s, it is more appropriate. According to several cdns of csdn, some games are only set to 12 cores, so different games are not necessarily supported. Basically, action games require a higher level of players. Our game framework is linear, that is, the output display and accept input are in the same thread, and the game processing input below 15 Gbit/s will look benzene, if the processor speed is higher than 20 Gb/s, the input is easily stuck in the buffer zone and cannot be processed. At this stage, try to reduce the number of workers. You cannot compare it with the case of unified 30 FPS when programming with dx on pc.
In this game with control of genie mobile as its main content, we do not encapsulate any game events. Our programs may be somewhat immature and it doesn't matter. Let's take a step.
1. Aircraft
Plane is a standard plane. Consists of three screens ,:
In the constructor, we add the initialization object statement for the aircraft:
Image img = ImageTools. getImage ("/pic/MyPlaneFrames.png ");
Plane = new GameObject (img, 24, 24 );
Initialize the status in gameInit () and center the position:
Plane. reset ();
Plane. moveto (screenwidth-plane.sprite.getWidth ()/2, (screenheight-plane.sprite.getHeight ()/2 );
Add the following to gameMain:
Plane. paint (g );
Next, let the plane move under control, mainly by adding Input Processing in gameMain. If the plane moves left, it will update the picture to the left of the plane. If the plane is right and vice versa, when no input is made, the plane 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 );

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.