Perfect processing of Java mobile game buttons

Source: Internet
Author: User

I have played some Java mobile games on the market, and found that many games have problems with key processing. They are either insensitive or do not support simultaneous pressing of multiple keys. as a hardcore professional game player, I really can't stand this kind of unfriendly game design. So the younger brother analyzed the specific reasons:

 

1) if you use midp1.0 to process consecutive key messages:

As required, use the three functions keypressed (INT keycode), keyreleased (INT keycode), keyrepeated (INT keycode)

Then, you can set a Boolean flag to achieve continuous buttons. Many articles on the Internet are also written in this way. You can look for them, but there is actually a very serious problem,

The button is not sensitive, especially when it is pressed, the response is very slow. Why?

This is because of the design defect of midp1.0. in midp1.0, the game's key response and the game's rendering are handled by the system thread and the game thread respectively, and the key response is often not timely, because the thread is different, it is easy to know the cause and solution, that is, to write the content in the keyrepeated (INT keycode) to the game drawing thread, and completely give up the function without keyrepeated (INT keycode !!!

After testing, the problem is solved, and the key response is smooth. Two keys can be pressed simultaneously,

 

2) If midp2.0 is used

2.0 in fact, the buttons and game rendering have been implemented in a thread, so the buttons are very sensitive. To perfectly process multiple keys and press them at the same time, you need to write complicated key logic by yourself,

If you do not need to be perfect, just use a few if () Statements for parallel operation, and the effect is good.

However, the wtk2.5 simulator has a key bug in midp2.0. Sometimes the press cannot be relaxed. You must press it again to release it. We recommend that you change the wtk2.3 simulator in midp2.0.

 

 

To sum up, there are two main causes of the key issue.

In midp1.0, a flag is not used, and continuous buttons cannot be implemented. Second, a flag is used to implement continuous buttons, but it is not sensitive due to thread reasons.

The solution is to set the flag and transfer all the content that should be written in keyrepeated (INT keycode) to the game rendering thread.

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.