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

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

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

Big-M Method and Two-Phase Method

Big-M Method The Big-M method of handling instances with artificial  variables is the “commonsense approach”. Essentially, the notion is to make the artificial variables, through their coefficients in the objective function, so costly or unprofitable that any feasible solution to the real problem would be preferred, unless the original instance possessed no feasible solutions at all. But this means that we need to assign, in the objective function, coefficients to the artificial variables that are either very small (maximization problem) or very large (minimization problem); whatever this value,let us call it Big M . In fact, this notion is an old trick in optimization in general; we  simply associate a penalty value with variables that we do not want to be part of an ultimate solution(unless such an outcome is unavoidable). Indeed, the penalty is so costly that unless any of the  respective variables' inclusion is warranted algorithmically, such variables will never be p