HTML5 game development Combat--attention point

Source: Internet
Author: User
Tags event listener jquery library

1.WebSocket is part of the HTML5 standard that Web pages can use to permanently connect to the socket server. This interface provides an event-driven connection to the server, which means that the client does not have to send a new data request to the server every other time period. When the data needs to be updated, the server can push the data directly to update the browser. One of the benefits of this feature is that players can interact with each other in real time. When a player does something, it sends the data to the server, and the server broadcasts an event to all the other connected browsers, letting them know what the player has done. This makes it possible to make HTML5 online games.

2. With the native support for HTML5 elements in modern browsers, it is no longer necessary for users to pre-install third-party plugins to play the game.

3. We place the JavaScript code before the body end tag and after all the contents of the page. Here's why you put your code in this position, not between the previous two tags.

4. Typically, browsers load and render content from top to bottom. If the JavaScript code is placed in the head section, the JavaScript code is loaded and the contents of the document may not have finished loading. In fact, if the browser loads JavaScript code in the middle of the page, it interrupts the rendering and loading in progress. That's why it's possible to put JavaScript code at the bottom of the page. In this way, the performance of the loaded content can be improved.

5.jQuery gives us a way to execute code after the page has been loaded, as follows:

JQuery (document). Ready (function ()

{

Here is the code

});

$ (function ()

{

Here is the code

});

6. There are several advantages to using jquery than simply using javascript:

Using jquery, you can select and modify DOM nodes with shorter code.

Short code is more useful for code, which is important for game development because game development often involves a lot of code.

Writing short code can speed up development.

Using the jquery library allows the code to support all major browsers without additional adjustments, and jquery wraps the script code to achieve its own cross-browser capabilities.

7. Assign a number to each key on the keyboard, and by getting the number, we can find out which key is being pressed. By listening to JQuery's KeyDown event listener, the event object will contain the key code when it is triggered. The key code can be obtained by invoking the which function of the key event object.

$ (document). KeyDown (function (e)

{

Console.log (E.which);

Switch (E.which)

{

Case 38://Press the UP key to handle

}

});

8. In most cases, the DOM element left and top properties can be styled using a format like 100px. The units are specified when the property is set, and when the property value is obtained, the value returned is the unit of the band. For example, when you call $ ("#paddleA"). CSS ("top"), the resulting value is 100px instead of 100. This will cause problems when performing mathematical operations on this value.

$ ("#paddleA"). CSS ("top") + 5, the return will be 100px5, not the result we want.

9.parseInt (String, radix) a string to parse, an optional parameter that indicates what system needs to be used in a number.

Parse ("5cm") returns 5; Parse ("FF", 16) returns 255

10. Because global variables are valid throughout the document, the probability of variable name collisions increases when different libraries are integrated into a Web page. A better approach would be to put the global variables used in an object.

11. Before you introduce the back visibility, all of the elements on the page should only be presented before them. Previously, the element had no concept of front or back because it had only one choice. Now, when CSS3 introduces a three-axis rotation concept, the element can be rotated 3D so that it has a back side.

12.CSS3 refers to a property called backface-visibility (back visibility) that defines whether you can see the back of the element. By default, it is visible.

HTML5 game development Combat--attention point

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.