Skip to main content

JSON Implementations in HTML5

JSON: HTML5 Game Implementations
  • JSON helps in getting image data.
Example: Image files name, width & height, etc
  • It is very light weight java data interchange format based on JavaScript object format.
  • It is Easy to implement as compare to XML.
  • JSON used to parse the object and JavaScript help in execute those parsed object.

Example:
JSONExample="frames": {

                        "chaingun.png": {                            //File name
                                    "frame": {
                                                "x": 1766,                   //X coordinate
                                                "y": 202,                    //Y coordinate
                                                "w": 42,                      //width
                                                "h": 34                                    //height
                                    },
                                    "rotated": false,                    //Rotated or not
                                    "trimmed": true,                     //trim(Discussed further)
                                    "spriteSourceSize": {
                                                "x": 38,
                                                "y": 32,
                                                "w": 42,
                                                "h": 34
                                    },
                                    "sourceSize": {
                                                "w": 128,
                                                "h": 128
                                    }
                        },

How to Parse JSON Data

  • Retrieve data from the server.
  • XML HttpRequest() allows JavaScript code to run on browser and fire request to server on specific URL.
  • Then Server uses the Response and request format.

Steps to send request.
    1. Create a XML request object à new XML HttpRequest()

    1. xhr.open (“GET”, ”URL”, Asynchronous)

    1. xhr.onload=function(){Body Code}

    1. xhr.send();

Explanation:
            var setup=function(){
            1. new XML HttpRequest()              //Create new XML httpRequest
2. xhr.open (“GET”, ”weapon.JSON”, true)  //method, resource url, bool
3. xhr.onload= function () {
            parsedJSON = JSON.parse(this.responseText);  //Body Code
console.log{ parsedJSON['frames']['chaingun_impact.png']['spriteSourceSize']['x']
};
4.xhr.send();

Atlases

Once you get the ability to manipulate the CANVAS, then it is necessary to work with its functionality. It is obvious if you develop a big application like games then it must contain many image files. It may be big images or small ones but you have a good set of images to implement in your game set.

To manage these small and big images you can use the concept of ATLASES.
Atlases reduce the complexity and enhance the working capability of game or application.

Modern browser can handle maximum of 6 connection or request from the server and after that all connection get blocked and it slow down that application. To enhance this you have to reduce the complexity of request by dividing one heavy request to small many requests. It reduces the load time of application.
To implement this strategy you have to use the concept of JSON.
Bind all small images into a big image and parse the image that you want to use. It reduces the server request and enhances the application on the performance basis.
This technique is called Texture Atlasing .  To implement this technique you can use a tool called Texture Packer. Texture Packer binds all the images into one big image and provides you to the way to parse your desire image easily by JSON technique. Image discussed about the parsing of particular image inside the box.


Let’s observer the format of Images as code:

"chaingun.png": {                                                   //File name1
                                                "frame": {
                                                "x": 1766,                    //input X coordinate
                                                "y": 202,                     //input Y coordinate 
                                                "w": 42,                     
                                                "h": 34                       
                                    },
                                    "rotated": false,                    //Rotated or not
                                    "trimmed": true,                   //trim to the desired object size
                                    "spriteSourceSize": {
                                                "x": 38,                        // output X coordinate
                                                "y": 32,                        //output Y coordinate
                                                "w": 42,                      //output width after trimmed
                                                "h": 34                                    //output height after trimmed
                                    },
                                    "sourceSize": {
                                                "w": 128,        //Image’s real width
                                                "h": 128          //Image’s real width
                                    }
                        },
                        "chaingun_impact.png": {          //File name 2
                                    "frame": {
                                                "x": 1162,
                                                "y": 322,
                                                "w": 38,
                                                "h": 34
                                    },
                                    "rotated": false,
                                    "trimmed": true,
                                    "spriteSourceSize": {
                                                "x": 110,
                                                "y": 111,
                                                "w": 38,
                                                "h": 34
                                    },
                                    "sourceSize": {
                                                "w": 256,
                                                "h": 256
                                    }
                        },


Comments

Popular posts from this blog

Inter-Organizational Value Chain

The value chain of   a company is part of over all value chain. The over all competitive advantage of an organization is not just dependent on the quality and efficiency of the company and quality of products but also upon the that of its suppliers and wholesalers and retailers it may use. The analysis of overall supply chain is called the value system. Different parts of the value chain 1.  Supplier     2.  Firm       3.   Channel 4 .   Buyer
Advantages and Disadvantages of EIS Advantages of EIS Easy for upper-level executives to use, extensive computer experience is not required in operations Provides timely delivery of company summary information Information that is provided is better understood Filters data for management Improves to tracking information Offers efficiency to decision makers Disadvantages of EIS System dependent Limited functionality, by design Information overload for some managers Benefits hard to quantify High implementation costs System may become slow, large, and hard to manage Need good internal processes for data management May lead to less reliable and less secure data

System Analysis and Design (SAD)

Introduction to System Analysis and Design (SAD) System are created to solve Problems. One can think of the systemsapproch as an organised way of dealing with a problem. In this dynamic world , the subject system analysis and design, mainly deals with the software development activities. This post include:- What is System? What are diffrent Phases of System Development Life Cycle? What are the component of system analysis? What are the component of system designing? What is System? A collection of components that work together to realize some objectives forms a system. Basically there are three major components in every system, namely input, processing and output. In a system the different components are connected with each other and they are interdependent. For example, human body represents a complete natural system. We are also bound by many national systems such as political system, economic system, educational system and so forth. The objective of the system demands tha...